public function get_content() { include 'languages/Languages.php'; echo <<<_END \t\t\t\t<h2>Report about gardens</h2> \t\t\t<table class='table-list'> \t\t\t\t<th>Garden</th><th>Plant Name</th><th>Plant Date</th><th>Days In Garden</th> _END; $query = "SELECT Name,PlantID,(SELECT Name FROM plants WHERE ID=PlantID),(SELECT SubName FROM plants WHERE ID=PlantID),PlantDate,EndDate FROM garden JOIN main ON Name=main.Garden WHERE EndDate='0000-00-00' AND PlantDate<>'0000-00-00' ORDER BY Name=0,-Name DESC, Name "; $result = mysql_query($query); if (!$result) { exit("Ошибка запроса: " . mysql_error()); } while ($row = mysql_fetch_array($result)) { $PlantDate = $row[4]; $EndDate = $row[5]; if ($EndDate == 00 - 00 - 00) { $Today = date('Y-m-d'); $DaysInGarden = GetDaysBetween($PlantDate, $Today); if ($Date_Format == "DD.MM.YYYY") { $PlantDate = date("d.m.Y", strtotime("{$PlantDate}")); } if ($Date_Format == "MM.DD.YYYY") { $PlantDate = date("m.d.Y", strtotime("{$PlantDate}")); } if ($Date_Format == "YYYY.MM.DD") { $PlantDate = date("Y.m.d", strtotime("{$PlantDate}")); } if ($row[3]) { $PlantName = ', ' . $row[3]; } else { $PlantName = ' '; } echo "<tr><td>{$row['0']}</td><td>{$row['2']}" . $PlantName . "</td><td>{$PlantDate}</td><td>{$DaysInGarden}</td></tr>"; } } echo "</table>"; }
public function get_content() { include 'languages/Languages.php'; $db_server = mysql_connect(HOST, USER, PASSWORD); if (!$db_server) { die("Невозможно поключится к базе данных" . mysql_error()); } mysql_select_db(DB) or die("Невозможно выбрать базу данных" . mysql_error()); //if all fields not empty, add date from fields to the DataBase if (isset($_POST['FamilyID']) && $_POST['Number'] && isset($_POST['TraySD'])) { $ID = ""; $SelectedPlant = mysql_fetch_array(mysql_query("SELECT ID FROM `plants` WHERE Name='" . $_POST['FamilyID'] . "'")); $PlantID = $SelectedPlant['ID']; $Number = $_POST['Number']; $Today = date('Y-m-d'); $TraySD = $_POST['TraySD']; if ($Date_Format == "DD.MM.YYYY") { $TraySDF = date("Y.m.d", strtotime("{$TraySD}")); } if ($Date_Format == "MM.DD.YYYY") { $TraySDF = date("Y.d.m", strtotime("{$TraySD}")); } if ($Date_Format == "YYYY.MM.DD") { $TraySDF = $TraySD; } if ($TraySDF == '1970.01.01') { $TraySDF = date('Y.m.d'); } $query = "INSERT INTO main VALUES" . "('{$ID}','{$PlantID}','{$Number}','{$TraySDF}','','','','')"; header("Location:?option=main_form"); if (!mysql_query($query, $db_server)) { echo "Cбой при вставке данных: {$query} <br />" . mysql_error() . "<br /><br />"; } unset($_POST['FamilyID']); unset($_POST['Number']); unset($_POST['TraySD']); } else { } if (isset($_POST['delete'])) { $DEL = $_POST['deleted']; $query = "DELETE FROM main WHERE ID='{$DEL}'"; if (!mysql_query($query, $db_server)) { echo "Сбой при удалении данных"; } } echo <<<_END \t\t\t<div class="plant_list"> \t\t\t<h2>Tray Starts</h2> \t\t<fieldset> \t\t\t<legend>Tray Starts</legend> _END; require_once "config.php"; $query = "SELECT * FROM main ORDER BY TrayStartDay"; $result = mysql_query($query); if (!$result) { die("Сбой при подключении к базе данных" . mysql_error()); } $rows = mysql_num_rows($result); function GetDaysBetween($date1, $date2) { $interval = (strtotime($date1) - strtotime($date2)) / (60 * 60 * 24); return abs(round($interval)); } echo <<<_END \t<form action="?option=main_form" method="POST" onsubmit="return test()"> \t\t\t<table class="table-list"> \t\t\t\t<th>{$LS_TrayStarts}</th><th id='field2'>#</th><th></th><th>Start Date</th><th>Days In Tray</th><th></th> \t\t\t\t<tr><td> _END; $query = "SELECT `name`,`subname` FROM `plants` ORDER BY `name`,`subname`"; $res = mysql_query($query); if (!$res) { exit("Ошибка запроса: " . mysql_error()); } if (mysql_num_rows($res) > 0) { echo "<select name='FamilyID' class='Select' id='field1'><option selected value=''></option>"; // В цикле выводим опции селекта while ($row = mysql_fetch_array($res)) { $Name = $row['name']; $SubName = $row['subname']; $Coma = ', '; if (!$SubName) { $Coma = ''; } $PlantName = $Name . $Coma . $SubName; echo '<option value="' . $row['name'] . '">' . $PlantName . '</option>'; } echo "</select>"; } echo '</td><td><input id="field2" type="text" class="NumberOfTray" name="Number" /></td> <td>trays</td><td><input type="text" class="MainInput" id="field3" name="TraySD"/></td> <td></td> <td id="special"><input type="submit" id="submbutton" value="' . $LS_Add . '"></td> </td></tr></form>'; $i = 1; $k = 0; for ($j = 0; $j < $rows; ++$j) { $row = mysql_fetch_row($result); $SelectedPlant = mysql_fetch_array(mysql_query("SELECT Name,id FROM `plants` WHERE ID='{$row['1']}'")); $PlantID = $SelectedPlant['Name']; $Today = date('Y-m-d'); $TraySD = $row[3]; $DaysInTray = GetDaysBetween($row[3], $Today); if ($row[6] == '0000-00-00') { $row[6] = ''; } if ($row[7] == '0000-00-00') { $row[7] = ''; } if ($row[6] != '') { $DaysInTray = ''; } if ($Date_Format == "YYYY.MM.DD") { $TrayStartDateF = date("Y.m.d", strtotime("{$TraySD}")); } if ($Date_Format == "MM.DD.YYYY") { $TrayStartDateF = date("m.d.Y", strtotime("{$TraySD}")); } else { if ($Date_Format == "DD.MM.YYYY") { $TrayStartDateF = date("d.m.Y", strtotime("{$TraySD}")); } } if ($DaysInTray == 0) { $DaysInTray = ''; } if ($row[7] == '') { echo "<tr><td>"; $query = "SELECT `name`,`subname`,id FROM `plants` ORDER BY `name`,`subname`"; $res = mysql_query($query); if (!$res) { exit("Ошибка запроса: " . mysql_error()); } if (mysql_num_rows($res) > 0) { if ($row[1] != '') { $BaseTray = $row[1]; $SelectedPlant = mysql_fetch_array(mysql_query("SELECT Name,SubName FROM `plants` WHERE ID='" . $BaseTray . "'")); $Name = $SelectedPlant['Name']; $SubName = $SelectedPlant['SubName']; if ($SubName) { $Coma = ', '; } else { $Coma = ' '; } $SelectedPlantName = $Name . $Coma . $SubName; } else { $PlantName = ''; } echo '<select onchange="reloadTrayStarts(this)" class="Select" name="' . $row[0] . '" id="' . $i . '">'; // В цикле выводим опции селекта while ($row1 = mysql_fetch_array($res)) { if ($row1['subname']) { $Coma = ', '; } else { $Coma = ' '; } $AllPlantName = $row1['name'] . $Coma . $row1['subname']; if ($AllPlantName == $SelectedPlantName) { echo '<option selected value="' . $Name . '">' . $SelectedPlantName . '</option>'; } else { echo '<option value="' . $AllPlantName . '">' . $AllPlantName . '</option>'; } } echo "</select>"; } echo "</td><td><input id='field2' type='text' class='NumberOfTray' onchange='reloadData(this.className,this.name,this.value)' value='" . $row[2] . "' name='" . $row[0] . "'/></td>\r\n\t\t<td>{$LS_trays}</td>\r\n\t\t<td>"; echo '<input type="text" class="MainInput" name="' . $row[0] . '" data-item="' . $Date_Format . '" id="TraySD" value="' . $TrayStartDateF . '"></input>'; echo "\t<td>{$DaysInTray}</td>\r\n\t\t\r\n\t\t\r\n\t\t</td>\r\n\t\t<td id='special'>\r\n\t\t<form action='?option=main_form' method='POST'>\r\n\t\t<input type='hidden' name='delete' value='yes'/>\r\n\t\t<input type='hidden' name='deleted' value='{$row['0']}'/>\r\n\t\t<input type='submit' id='submbutton' value='{$LS_Delete}'>\r\n\t\t</form>\r\n\t\t</fieldset>\r\n\t\t</td></tr>"; ++$i; --$k; } } echo <<<_END \t\t\t\t</tr> \t\t\t</table> \t\t\t</fieldset> \t\t\t \t\t\t \t\t\t</div> \t\t _END; }
public function get_content() { include 'languages/Languages.php'; if (isset($_POST['onload'])) { $value2 = $_POST['onload']; } else { $value2 = 'All'; } $queryToMain = mysql_query("SELECT DISTINCT PlantID FROM main WHERE EndDate = '0000-00-00' AND Garden<>''"); echo <<<_END <h2>Report about plants</h2> \t\t\t<form method='POST' action='?option=plant_report'> \t\t\t<div class='plant-navigation'> \t\t\t<input type='submit' id='All' class='All' value='All' style="font-weight:bold;" onclick="Empty(this)"> \t\t\t _END; if (mysql_num_rows($queryToMain) > 0) { while ($row = mysql_fetch_array($queryToMain)) { $queryToGarden = mysql_query("SELECT Name FROM plants WHERE ID = '{$row['PlantID']}'"); while ($inputButtons = mysql_fetch_array($queryToGarden)) { echo <<<_END \t\t\t<input type="submit" class='{$inputButtons['Name']}' id='{$inputButtons['Name']}' onclick="Empty(this)" value='{$inputButtons['Name']}'"/> _END; } } } echo <<<_END \t\t\t\t<!--When click give input with id must value and when page will load give value2(name of button) --> \t\t\t\t<input type='hidden' id="onload" name='onload' value='{$value2}'/> \t\t\t</form> \t\t\t</div> \t\t\t\t<table class='table-list'> \t\t\t\t\t<th>Plant Name</th><th>Garden</th><th>Plant Date</th><th>Days in garden</th> _END; function GetDaysBetween($date1, $date2) { $interval = (strtotime($date1) - strtotime($date2)) / (60 * 60 * 24); return abs(round($interval)); } if ($value2 != 'All') { $query = "SELECT * FROM `plants` WHERE name='{$value2}' "; $result = mysql_query($query); if (!$result) { exit("ERROR: " . mysql_error()); } } else { $query = "SELECT * FROM `plants` ORDER BY `name`"; } $result = mysql_query($query); if (!$result) { exit("ERROR: " . mysql_error()); } if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) { $queryToGarden = "SELECT Garden, PlantDate,EndDate FROM \t`main` WHERE PlantID='{$row['0']}' AND EndDate = '0000-00-00' AND Garden<>'' AND PlantDate<>'0000-00-00' ORDER BY PlantDate"; $resultGarden = mysql_query($queryToGarden); if (!$resultGarden) { exit("ERROR: " . mysql_error()); } if (mysql_num_rows($resultGarden) > 0) { while ($rowMain = mysql_fetch_array($resultGarden)) { $PlantDate = $rowMain[1]; $EndDate = $rowMain[2]; $Today = date('Y-m-d'); $GardenName = $rowMain[0]; $DaysInGarden = GetDaysBetween($PlantDate, $Today); if ($Date_Format == "DD.MM.YYYY") { $PlantDate = date("d.m.Y", strtotime("{$PlantDate}")); } if ($Date_Format == "MM.DD.YYYY") { $PlantDate = date("m.d.Y", strtotime("{$PlantDate}")); } if ($Date_Format == "YYYY.MM.DD") { $PlantDate = date("Y.m.d", strtotime("{$PlantDate}")); } if ($row[3]) { $PlantName = ', ' . $row[3]; } else { $PlantName = ' '; } echo "<tr><td>{$row['2']}" . "{$PlantName}" . "</td><td>{$GardenName}</td><td>{$PlantDate}</td><td>{$DaysInGarden}</td></tr>"; } } } } echo <<<_END \t\t\t\t</table>\t _END; }