From: Sean M. P. <peg...@us...> - 2008-06-10 14:15:25
|
Update of /cvsroot/helpmeict/Helpdesk/system In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv16707/system Added Files: Tag: v1_r1 fixRemarks.php Log Message: Adding fixRemarks.php. --- NEW FILE: fixRemarks.php --- <?php /* fixRemarks.php Corrects time field in database records by adding minutes from the comments. NOTE: db.php assumes the script is in one level above system, so this script needs to be called from one level above using the provided symlink, even though it belongs in here. What's the best way to fix this? ## PAGE CONTAINS HANDYANDY MYSQL MODS ## ## Copyright (C) 2005 Andy Deakin (handyandy.org.uk) ## ---- Copyright (C) 2003 Central Manchester CLC Copyright (C) 2003 David Thorne (dav...@gm...) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Call this script from the root of the helpdesk system! require_once 'system/db.php'; echo "<pre>"; echo "Correcting minutes in time logs in remarks table...\n\n"; $record = db_recordset("SELECT id FROM tbl_remarks ORDER BY id DESC LIMIT 1"); $highest = $record[0][id]; $record = db_recordset("SELECT id FROM tbl_remarks ORDER BY id ASC LIMIT 1"); $lowest = $record[0][id]; echo "Remark ID range: $lowest - $highest\n\n"; for ($id=$lowest;$id<=$highest;$id++) { $record = db_recordset("SELECT remark,time FROM tbl_remarks WHERE id=$id"); $remark=split(" ",$record[0][remark]); $whereMinutes=0; foreach($remark as $key => $value) { if(eregi("minut.",$value)) { $whereMinutes=$key; break; } } if ($whereMinutes) { // If minutes were reported $minutes=intval($remark[$whereMinutes-1]); if ($minutes>0) { echo "Remark ID: $id, Minutes gleaned: $minutes, Old record: ".$record[0][time]; //echo "Remark text: ".$record[0][remark]."\n"; // For testing $time=split(":",$record[0][time]); if ($time[1]=="00") { if ($minutes<10) $time[1]="0$minutes"; else $time[1]=$minutes; $newTime=implode(":",$time); echo ", New record: $newTime\n"; $sql = "UPDATE tbl_remarks SET time = '$newTime' WHERE id=$id"; db_send($sql); } else echo ", WARNING: Record already has minutes entered. Leaving unchanged.\n"; } } } echo "\nTime record correction complete.\n"; echo "</pre>"; ?> |