function editUser($u, $p) { $fileName = file('/etc/squid3/basic.passwd'); $users = array(); foreach ($fileName as $key => $value) { list($k, $v) = preg_split("/:/", $value); print "key = " . $k . " :: val = " . $v . "<br>"; $users[$k] = $v; } print "<br>==== BEFORE EDITING ====<br>"; displayArray($users); $users[$u] = htpasswd($p); print "<br>==== AFTER EDITING ====<br>"; displayArray($users); //print $u." gets new password ".$p." {".$users[$u]."}<br>"; if (!($fp = fopen('/etc/squid3/basic.passwd', 'w+'))) { print "Cannot open file (" . $fileName . ")"; exit; } if ($fp) { foreach ($users as $uname => $pass) { fwrite($fp, $uname . ":" . $pass); } fclose($fp); } }
function getPlotBarData($channelID) { global $DEBUG; global $names; // #query average temp for days $sqlQuery = "SELECT day1, min1, avg1, max1 FROM (" . "\tSELECT * FROM ( " . "\t\tSELECT channel, " . "\t\tDAY(date_time) as day1, " . "\t\tMAX(temp)*.1 as max1, " . "\t\tAVG(temp)*.1 as avg1, " . "\t\tMIN(temp)*.1 as min1, " . "\t\tAVG(humidity) as humi1, " . "\t\tdate_time, " . "\t\tDATE_FORMAT(date_time, '%j') as dayofyear " . "\t\tFROM `avrdb`.`avrtemp` " . "\t\tWHERE channel=" . $channelID . " " . "\t\tGROUP BY " . "\t\tday1, dayofyear " . "\t\tWITH ROLLUP " . "\t\t) as myroundup " . "\tWHERE day1 is not null " . "\tAND DATE_FORMAT(now(), '%j') - dayofyear < 14 " . "\tORDER BY date_time ASC) as mydays " . "order by date_time ASC " . "LIMIT 14 " . ";"; $sqlResult = mysql_query($sqlQuery); if ($sqlResult) { while ($row = mysql_fetch_assoc($sqlResult)) { $dataResult[] = $row; } } else { $dataResult[] = array(array(1, 2), array(3, 4)); } if ($DEBUG) { displayArray($dataResult); } return $dataResult; }
<?php /** * create a folder * @author Logan Cai (cailongqun [at] yahoo [dot] com [dot] cn) * @link www.phpletter.com * @since 22/May/2007 * */ require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "inc" . DIRECTORY_SEPARATOR . "config.php"; @ob_start(); displayArray($_POST); writeInfo(@ob_get_clean()); echo "{"; $error = ""; $info = ""; /* $_POST['new_folder'] = substr(md5(time()), 1, 5); $_POST['currentFolderPath'] = "../../uploaded/";*/ if (CONFIG_SYS_VIEW_ONLY || !CONFIG_OPTIONS_NEWFOLDER) { $error = SYS_DISABLED; } elseif (empty($_POST['new_folder'])) { $error = ERR_FOLDER_NAME_EMPTY; } elseif (!preg_match("/^[a-zA-Z0-9_\\- ]+\$/", $_POST['new_folder'])) { $error = ERR_FOLDER_FORMAT; } else { if (empty($_POST['currentFolderPath']) || !isUnderRoot($_POST['currentFolderPath'])) { $error = ERR_FOLDER_PATH_NOT_ALLOWED; } elseif (file_exists(addTrailingSlash($_POST['currentFolderPath']) . $_POST['new_folder'])) { $error = ERR_FOLDER_EXISTS; } else { include_once CLASS_FILE;
function dataStartEnd($mystart, $myend) { global $DEBUG; //Get the data from the database $sqlQuery = "SELECT * FROM " . "(SELECT DATE_FORMAT(date_time,'%Y%m%d%H%i') as dtime, temp/10 as temp1, humidity, channel, state FROM avrtemp " . " GROUP BY dtime " . " where channel=4 ORDER BY dtime ASC) as bad " . " WHERE dtime > " . $mystart . " AND dtime < " . $myend . " " . ";"; if ($DEBUG) { echo "<p>" . $sqlQuery . "</p>"; } $sqlResult = mysql_query($sqlQuery); if ($sqlResult) { // $dataResult = mysql_fetch_assoc($sqlResult); while ($row = mysql_fetch_assoc($sqlResult)) { $dataResult[] = $row; } //draw line graph $countData = count($dataResult); //Set chd parameter to no value $chd = ''; $chd .= "['Zeit','Temperatur','Luftfeuchte'],"; //Start to compile the data for ($row = 0; $row < $countData; $row++) { //Check for a value if one exists, add to $chd if (isset($dataResult[$row]['dtime']) && isset($dataResult[$row]['temp1']) && isset($dataResult[$row]['humidity'])) { $chd .= "['" . $dataResult[$row]['dtime'] . "'," . $dataResult[$row]['temp1'] . "," . $dataResult[$row]['humidity'] . "],\r\n"; } } if ($DEBUG) { echo "<p>" . $chd . "</p>"; } $channelID = 4; // see "chart_div".$channelID // see https://developers.google.com/chart/interactive/docs/gallery/linechart echo " <script type='text/javascript' src='https://www.google.com/jsapi'></script>\r\n"; echo " <script type='text/javascript'>\r\n"; echo " google.load('visualization', '1', {packages:['corechart']});\r\n"; echo " google.setOnLoadCallback(drawChart);\r\n"; echo " var myStart;\r\n"; echo " var myEnd;\r\n"; echo " var bSetStart=true;\r\n"; echo " function drawChart() {\r\n"; echo " var data = google.visualization.arrayToDataTable([\r\n"; echo $chd . ""; echo " \r\n]);"; echo "\n\n"; echo " var options = {\r\n"; echo " title: 'Temperatur und Luftfeuchte von " . "Bad" . "',"; // echo " vAxis: {maxValue: 25, minValue: -10}"; //######## DO NOT USE COMMENTS inside options! ###### echo "\t\t\tseries: {"; echo "\t\t\t 0:{targetAxisIndex:0, color: 'red'},"; echo "\t\t\t 1:{targetAxisIndex:1, color: 'blue'}"; echo "\t\t\t},\r\n"; echo "\t\t\tvAxes: {"; echo "\t\t\t 0: {title:'Temperatur',textStyle:{color: 'red'}, maxValue: 25, minValue: -10},"; echo "\t\t\t 1: {title:'Luftfeuchte',textStyle:{color: 'blue'},maxValue: 100, minValue: 0}"; echo "\t\t\t}\r\n"; echo " };\r\n"; echo "\n\n"; echo " var chart = new google.visualization.LineChart(document.getElementById('chart_div" . $channelID . "'));\r\n"; echo " function selectHandler(e) {\r\n"; // echo " alert('hello'); \r\n"; echo " var selection = chart.getSelection();\r\n"; echo " if(selection.length>0 && typeof selection[0].row != 'undefined') {\r\n"; echo " //alert('That is row/column no. '+selection[0].row+'/'+selection[0].column);\r\n"; echo " if(bSetStart){\r\n"; echo " document.getElementById('start').value=data.getValue(selection[0].row,0);\r\n"; echo " bSetStart= !bSetStart;\r\n"; echo " //alert('data='+data.getValue(selection[0].row,0));\r\n"; echo " }\r\n"; echo " else{\r\n"; echo " document.getElementById('end').value=data.getValue(selection[0].row,0);\r\n"; echo " bSetStart= !bSetStart;\r\n"; echo " }//if bSetStart\r\n"; echo " }//if selection\r\n"; echo " return;\r\n"; echo " }//selectHandler\r\n"; // echo "\t // Must wait for the ready event in order to"; echo " // request the chart and subscribe to 'onmouseover'.\r\n"; echo " google.visualization.events.addListener(chart, 'ready', onReady);\r\n"; echo " function onReady() {\r\n"; // Every time the table fires the "select" event, it should call your // selectHandler() function. echo " google.visualization.events.addListener(chart, 'select', selectHandler);\r\n"; echo " }"; //Draw the chart echo " chart.draw(data, options);\r\n"; echo " } //end of function drawChart\r\n"; echo " </script>\r\n"; if ($DEBUG) { displayArray($dataResult); } $countData = count($dataResult); } else { echo "<p>NO DATA</p>"; } return $dataResult; }
function showBarDays($channelID) { global $DEBUG; global $names; // #query average temp for days $sqlQuery = "SELECT * FROM (" . "\tSELECT * FROM ( " . "\t\tSELECT channel, " . "\t\tDAY(date_time) as day1, " . "\t\tAVG(temp)*.1 as temp1, " . "\t\tdate_time, " . "\t\tDATE_FORMAT(date_time, '%j') as dayofyear " . "\t\tFROM `avrdb`.`avrtemp` " . "\t\tWHERE channel=" . $channelID . " " . "\t\tGROUP BY " . "\t\tday1, dayofyear " . "\t\tWITH ROLLUP " . "\t\t) as myroundup " . "\tWHERE day1 is not null " . "\tAND DATE_FORMAT(now(), '%j') - dayofyear < 14 " . "\tORDER BY date_time ASC) as mydays " . "order by date_time ASC" . ";"; $sqlResult = mysql_query($sqlQuery); $dataResult = mysql_fetch_assoc($sqlResult); while ($row = mysql_fetch_assoc($sqlResult)) { $dataResult[] = $row; } // 'month1', 'day1', 'hour1', 'temp1' // '9', '4', '18', '16.95000' if ($DEBUG) { displayArray($dataResult); } $countData = count($dataResult); //count number of data //Set chd parameter to no value $chd = ''; // $chd.="['month1', 'day1', 'hour1', 'temp1'],"; $chd .= "['day1', 'temp1'],"; //Start to compile the data for ($row = 0; $row < $countData; $row++) { //Check for a value if one exists, add to $chd if (isset($dataResult[$row]['day1'])) { $chd .= "['" . $dataResult[$row]['day1'] . "'" . "," . $dataResult[$row]['temp1'] . "],\n"; } } if ($DEBUG) { echo "<p>DEBUG</p>"; echo "<p>" . $chd . "</p>"; } // see https://developers.google.com/chart/interactive/docs/gallery/linechart echo " <script type='text/javascript' src='https://www.google.com/jsapi'></script>"; echo " <script type='text/javascript'>"; echo " google.load('visualization', '1', {packages:['corechart']});"; echo " google.setOnLoadCallback(drawChart);"; echo " function drawChart() {"; echo " var data = google.visualization.arrayToDataTable(["; echo $chd; // echo " ['Year', 'Sales', 'Expenses'],"; // echo " ['2004', 1000, 400],"; // echo " ['2005', 1170, 460],"; // echo " ['2006', 660, 1120],"; // echo " ['2007', 1030, 540]"; echo " ]);"; echo ""; echo " var options = {"; // echo " title: 'Temperatur / Stunde'"; /* echo " vAxes:["; echo " {title:'Temperatur',textStyle:{color: 'blue'}}, // axis 0"; echo " {title:'Luftfeuchte',textStyle:{color: 'red'}} // Axis 1"; echo " ]"; */ echo " title: 'Temperatur von " . $names[$channelID] . "', "; echo " vAxis: {maxValue: 30, minValue: -10}"; echo " };"; echo ""; // echo " var chart = new google.visualization.LineChart(document.getElementById('chart_div".$channelID."'));"; echo " var chart = new google.visualization.ColumnChart(document.getElementById('chart_div" . $channelID . "'));"; echo " chart.draw(data, options);"; // echo " chart.draw(data, {title:'Temperatur/Stunde', vAxis: {maxValue=}});"; echo " }"; echo " </script>"; return; }
function shuffleArray(&$array) { //Create and init tem array $tempQuantity = count($array); $tempArr = array(); for ($i = 0; $i < $tempQuantity; $i++) { $tempArr[$i] = FALSE; } //Shuffle input array for ($i = 1; $i <= $tempQuantity; $i++) { while (TRUE) { $temp = mt_rand(0, $tempQuantity - 1); if (!$tempArr[$temp]) { //if FALSE $tempArr[$temp] = $array[$i]; break; } } } //Return result via link $array = $tempArr; } //MAIN LOOP arrayInit($Arr, $quantity); displayArray($Arr); shuffleArray($Arr); displayArray($Arr); // Output execution time for script $time = microtime(TRUE) - $start; echo "<br />" . "<br />"; printf('Script are executed %.8F sec.', $time);
<div id="menu"> <h1><a href="http://localhost:8888/Gits/notes/">Martin Campillo</a></h1> <p>Carnet de notes, travaux en cours et reflexions diverses.</p> <?php require_once "./php/functions.php"; $root = "./content/"; displayArray(sortArray(createArray($root), "date")); ?> <div id="footer"> <div class="colorSwitch night"> <input type="checkbox" id="colorSwitch" checked /> <label for="colorSwitch"></label> </div> <h6>Version 0.0.1 <br> <a href="https://github.com/fclmprod/notes/">github.com/fclmprod/notes/</a></h6> </div> <script src="./js/main.js"></script> </div>
$conn = new PDO("mysql:host={$dbhost};dbname={$dbname}", $dbuser, $dbpass); } catch (PDOException $pe) { die('Connection error, because ' . $pe->getMessage()); } function mySelectPDO($what, $from, $where, $order = '') { global $conn; $q = "SELECT " . implode($what, ',') . " FROM " . implode($from) . " WHERE " . implode($where, " AND "); $r = $conn->query($q); return $r; } $what = array('first_name', 'last_name', 'u_name', 'email'); $from = array('users'); $where = array('user_id<10'); $result = mySelectPDO($what, $from, $where); $result->setFetchMode(PDO::FETCH_ASSOC); while ($r = $result->fetch()) { displayArray($r); } // Prepare goes outside the loop $sql = $conn->prepare("SELECT user_id,first_name,last_name FROM users WHERE u_name = :uname"); $sql->bindParam(':uname', $uname); $users = array('knichel', 'klobk', 'myerr', 'ziburaz'); foreach ($users as $user) { $uname = $user; $sql->execute(); $sql->setFetchMode(PDO::FETCH_ASSOC); $r = $sql->fetch(); //print_r($r); //print "<br />"; }
/** * create a folder * @author Logan Cai (cailongqun [at] yahoo [dot] com [dot] cn) * @link www.phpletter.com * @since 22/May/2007 * */ require_once '../../config/config.inc.php'; require_once '../init.php'; require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "inc" . DIRECTORY_SEPARATOR . "config.php"; @ob_start(); $safe_post = array(); foreach ($_POST as $key => $value) { $safe_post[Tools::safeOutput($key)] = Tools::safeOutput($value); } displayArray($safe_post); writeInfo(@ob_get_clean()); echo "{"; $error = ""; $info = ""; /* $_POST['new_folder'] = substr(md5(time()), 1, 5); $_POST['currentFolderPath'] = "../../uploaded/";*/ if (CONFIG_SYS_VIEW_ONLY || !CONFIG_OPTIONS_NEWFOLDER) { $error = SYS_DISABLED; } elseif (empty($_POST['new_folder'])) { $error = ERR_FOLDER_NAME_EMPTY; } elseif (!preg_match("/^[a-zA-Z0-9_\\- ]+\$/", $_POST['new_folder'])) { $error = ERR_FOLDER_FORMAT; } elseif (empty($_POST['currentFolderPath']) || !isUnderRoot($_POST['currentFolderPath'])) { $error = ERR_FOLDER_PATH_NOT_ALLOWED; } elseif (file_exists(addTrailingSlash($_POST['currentFolderPath']) . $_POST['new_folder'])) {
<?php $host = '192.168.8.3'; $dbname = 'Gradebook'; $user = '******'; $pass = '******'; $conn = mssql_connect($host, $user, $pass); mssql_select_db("Gradebook", $conn); if (!$conn) { die("Error connecting to mssql server\n"); } function displayArray($a) { print "<pre><br />"; print_r($a); print "</pre><br />"; } $query = "\nSELECT\n\tClassByTeacher.SectionID, ClassByTeacher.username, ClassByTeacher.tsn, ClassByTeacher.BuildingID, ClassByTeacher.SchoolYear, ClassByTeacher.TakesAttendance,\n\tUSERS.teacher as isTeacher, USERS.uid as TGUID,\n\tClassRoster.STGUID, ClassRoster.Active as isActive,\n\tStudentDemographicData.FirstName, StudentDemographicData.LastName\nFROM\n\tClassByTeacher, USERS, ClassRoster, StudentDemographicData\nWHERE\n\tClassByTeacher.SchoolYear='2010-2011' AND\n\t((ClassByTeacher.BuildingID=13)OR(ClassByTeacher.BuildingID=14)) AND\n\tClassByTeacher.TakesAttendance='True' AND\n\tUSERS.username=ClassByTeacher.username AND\n\tClassRoster.SectionID=ClassByTeacher.SectionID AND\n\tClassRoster.Active='True' AND\nStudentDemographicData.STGUID=ClassRoster.STGUID\nORDER BY\n\tClassByTeacher.username, ClassByTeacher.tsn"; print $query; $result = mssql_query($query, $conn); while ($row = mssql_fetch_assoc($result)) { displayArray($row); }
* * NO NO NO * Dont set to inactive for ALL rosters, only the ones where the course is a CORE class * Otherwise teacher created classes (ie integrated) will get disabled.... */ if ($manual) { print "Working on Rosters\n"; } $msg = ''; $error = false; $currentSchoolYear = get_current_school_year(); $sql = "UPDATE student2class SET isActive='N' where class_id IN (\n SELECT class_id FROM classes, courses\n WHERE classes.course_id=courses.course_id\n AND courses.school_year_id = " . $currentSchoolYear . "\n AND courses.isCore='Y')"; //$err = $db->query($sql); $regi = array(); $smsClassRosters = make_array_from_sql(getClassRostersFromSMS(), 'ms'); displayArray($smsClassRosters); exit; $q3aitClassRosters = make_assoc_array_from_sql(getClassRostersForSMS(), 'SectionID', 'my'); $q3aitUsers = make_assoc_array_from_sql(getCurrentStudentsForSMS(), 'STGUID', 'my'); $q3aitCourses = make_assoc_array_from_sql(getCoursesForSMS(), 'SectionID', 'my'); $register = array(); // user_id, class_id //displayArray($smsClassRosters);exit; //displayArray($q3aitCourses); //displayArray($q3aitUsers); foreach ($smsClassRosters as $row) { if (array_key_exists($row['SectionID'], $q3aitCourses)) { if (array_key_exists($row['STGUID'], $q3aitUsers)) { if ($row['DateExited'] == NULL) { $student_id = $regi['student_id'] = $q3aitUsers[$row['STGUID']]['user_id']; $course_id = $regi['course_id'] = $q3aitCourses[$row['SectionID']]['course_id'];
function showLineChart($channelID) { global $DEBUG; global $names; //Get the data from the database $sqlQuery = "SELECT * FROM ( " . "SELECT * FROM ( " . "SELECT channel, " . "DATE_FORMAT(date_time,'%H') as hour1, " . "DAY(date_time) as day1, " . "AVG(temp)*.1 as temp1, " . "ROUND(AVG(humidity)) as humi1, " . "date_time, " . "DATE_FORMAT(date_time, '%j') as dayofyear " . "FROM `avrdb`.`avrtemp` " . "WHERE channel=" . $channelID . " " . "GROUP BY " . "day1, hour1, dayofyear " . "WITH ROLLUP " . ") as myroundup " . "WHERE day1 is not null AND hour1 is NOT NULL " . "AND ((DATE_FORMAT(now(), '%j') - dayofyear) < 2) " . "ORDER BY date_time DESC LIMIT 48 " . ") as sorted_hours " . "order by date_time asc; "; $sqlResult = mysql_query($sqlQuery); $dataResult = mysql_fetch_assoc($sqlResult); while ($row = mysql_fetch_assoc($sqlResult)) { $dataResult[] = $row; } if ($DEBUG) { displayArray($dataResult); } $countData = count($dataResult); if ($countData < 48) { echo "<h3>Temperatur und Luftfeuchte von " . $names[$channelID] . "</h3>zu wenig daten letzte 48 Stunden!<br>"; return; } //Set chd parameter to no value $chd = ''; //Limit $limit = 10; /* DataArrayTable [ ["time", Temperature1, Temperature2, Temperature3], ["2013-08-31 14:43:59", 19.9, 20.3, 21.0], ... ] */ // $chd.="['Zeit','Temperatur'],"; $chd .= "['Zeit','Temperatur','Luftfeuchte'],"; //Start to compile the data for ($row = 0; $row < $countData; $row++) { //Check for a value if one exists, add to $chd if (isset($dataResult[$row]['hour1']) && isset($dataResult[$row]['temp1']) && isset($dataResult[$row]['humi1'])) { $chd .= "['" . $dataResult[$row]['hour1'] . "'," . $dataResult[$row]['temp1'] . "," . $dataResult[$row]['humi1'] . "],"; } } if ($DEBUG) { echo "<p>DEBUG</p>"; echo "<p>" . $chd . "</p>"; } // see https://developers.google.com/chart/interactive/docs/gallery/linechart echo " <script type='text/javascript' src='https://www.google.com/jsapi'></script>"; echo " <script type='text/javascript'>"; echo " google.load('visualization', '1', {packages:['corechart']});"; echo " google.setOnLoadCallback(drawChart);"; echo " function drawChart() {"; echo " var data = google.visualization.arrayToDataTable(["; echo $chd . ""; // echo " ['Year', 'Sales', 'Expenses'],"; // echo " ['2004', 1000, 400],"; // echo " ['2005', 1170, 460],"; // echo " ['2006', 660, 1120],"; // echo " ['2007', 1030, 540]"; echo " ]);"; echo "\n\n"; echo " var options = {"; echo " title: 'Temperatur und Luftfeuchte von " . $names[$channelID] . "',"; // echo " vAxis: {maxValue: 25, minValue: -10}"; //######## DO NOT USE COMMENTS inside options! ###### echo "\t\t\tseries: {"; echo "\t\t\t 0:{targetAxisIndex:0, color: 'red'},"; echo "\t\t\t 1:{targetAxisIndex:1, color: 'blue'}"; echo "\t\t\t},"; echo "\t\t\tvAxes: {"; echo "\t\t\t 0: {title:'Temperatur',textStyle:{color: 'red'}, maxValue: 25, minValue: -10},"; echo "\t\t\t 1: {title:'Luftfeuchte',textStyle:{color: 'blue'},maxValue: 100, minValue: 0}"; echo "\t\t\t}"; echo " };"; echo "\n\n"; echo " var chart = new google.visualization.LineChart(document.getElementById('chart_div" . $channelID . "'));"; echo " chart.draw(data, options);"; echo " } //end of function drawChart"; echo " </script>"; return; }
<?php require '_configPath.php'; require $configPath . 'config.php'; require $_CONF['webRoot'] . 'functionLib.php'; /** * MySQL */ $db = new mysqli($_CONF['DB_host'], $_CONF['DB_user'], $_CONF['DB_pass'], $_CONF['DB_name']); if (mysqli_connect_errno()) { die("There was an error connecting to the database: " . mysqli_connect_error()); } /** * MSSQL */ $host = '192.168.8.3'; $dbname = 'SMS'; $user = '******'; $pass = '******'; $conn = mssql_connect($host, $user, $pass); mssql_select_db("SMS", $conn); if (!$conn) { die("Error connecting to mssql server\n"); } $smsStudents = make_assoc_array_from_sql(getCurrentStudentsFromSMS(), 'STGUID', 'ms'); displayArray($smsStudents); mssql_close($conn);