From: Karsten D. <k-...@us...> - 2006-04-27 11:57:11
|
Update of /cvsroot/moregroupware/mgw/modules/admin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32207/modules/admin Modified Files: workplacemanager.php Log Message: Sort capability for workplaces Index: workplacemanager.php =================================================================== RCS file: /cvsroot/moregroupware/mgw/modules/admin/workplacemanager.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** workplacemanager.php 18 Nov 2003 19:41:40 -0000 1.1 --- workplacemanager.php 27 Apr 2006 11:57:00 -0000 1.2 *************** *** 33,38 **** $gname = $conn->QMagic($_POST["worklocname"]); $gdesc = $conn->QMagic($_POST["description"]); ! $sql="INSERT INTO mgw_workplace (id, name, description, lu_user, lu_date) VALUES ($id, $gname, $gdesc, ".$_SESSION["MGW"]->userid.", ".$conn->DBTimeStamp(time()).")"; if(!$conn->Execute($sql)) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__)); --- 33,48 ---- $gname = $conn->QMagic($_POST["worklocname"]); $gdesc = $conn->QMagic($_POST["description"]); + $gsort = (int)$_POST["sort_order"]; ! // find max sort order ! $sql="select max(sort_order) from mgw_workplace"; ! $max_sort = $conn->GetOne($sql); ! if ($max_sort === FALSE) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__)); ! if ($gsort < 1 || $gsort > $max_sort) $gsort = $max_sort + 1; ! else { ! $sql = "UPDATE mgw_workplace SET sort_order=sort_order+1 WHERE sort_order >= $gsort"; ! if(!$conn->Execute($sql)) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__)); ! } ! $sql="INSERT INTO mgw_workplace (id, name, description, sort_order, lu_user, lu_date) VALUES ($id, $gname, $gdesc, $gsort, ".$_SESSION["MGW"]->userid.", ".$conn->DBTimeStamp(time()).")"; if(!$conn->Execute($sql)) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__)); *************** *** 70,75 **** $gname = $conn->QMagic($_POST["worklocname"]); $gdesc = $conn->QMagic($_POST["description"]); ! ! $sql="update mgw_workplace set name=$gname, description=$gdesc, lu_user=".$_SESSION["MGW"]->userid.", lu_date=". $conn->DBTimeStamp(time()). " WHERE id=$id"; if(!$conn->Execute($sql)) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__)); } --- 80,119 ---- $gname = $conn->QMagic($_POST["worklocname"]); $gdesc = $conn->QMagic($_POST["description"]); ! $gsort = (int)$_POST["sort_order"]; ! // adjust sort orders ! // find original sort order and highest sort order ! $sql="select sort_order from mgw_workplace where id=$id"; ! $orig_sort = $conn->GetOne($sql); ! if ($orig_sort === FALSE) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__)); ! $sql="select max(sort_order) from mgw_workplace"; ! $max_sort = $conn->GetOne($sql); ! if ($max_sort === FALSE) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__)); ! // if max_sort is null, establish sort order ! if ($max_sort < 1 || $orig_sort < 1) { ! $max_sort = 0; ! $sql = "SELECT id FROM mgw_workplace"; ! if(!$workplace_ids = $conn->GetCol($sql)) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__)); ! foreach ($workplace_ids as $workplace_id) { ! $max_sort++; ! $sql = "UPDATE mgw_workplace SET sort_order=$max_sort WHERE id=$workplace_id"; ! if (!$conn->Execute($sql)) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__)); ! // prevent resorting ! if ($workplace_id == $id) $gsort = $orig_sort = $max_sort; ! } ! } ! // if new > highest, new = highest ! if ($gsort > $max_sort) $gsort = $max_sort; ! if ($gsort < 1) $gsort = $orig_sort; ! // if original == new, do nothing ! if ($gsort > $orig_sort) { ! // if new > original, adjust -1 original to new ! $sql = "update mgw_workplace set sort_order=sort_order-1 where sort_order <= $gsort and sort_order > $orig_sort"; ! if(!$conn->Execute($sql)) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__)); ! } elseif ($gsort < $orig_sort) { ! // if new < original, adjust +1 new to original ! $sql = "update mgw_workplace set sort_order=sort_order+1 where sort_order >= $gsort and sort_order < $orig_sort"; ! if(!$conn->Execute($sql)) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__)); ! } ! $sql="update mgw_workplace set name=$gname, description=$gdesc, sort_order=$gsort, lu_user=".$_SESSION["MGW"]->userid.", lu_date=". $conn->DBTimeStamp(time()). " WHERE id=$id"; if(!$conn->Execute($sql)) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__)); } *************** *** 80,85 **** --- 124,137 ---- if (isset($_GET["view"]) && $_GET["view"] == "delete"){ $id = (int) $_GET["id"]; + // get sort order + $sql = "SELECT sort_order FROM mgw_workplace WHERE id=$id"; + $sort_order = $conn->GetOne($sql); + if ($sort_order === FALSE) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__)); + // delete entry $sql = "DELETE FROM mgw_workplace WHERE id=$id"; if(!$conn->Execute($sql)) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__)); + // realign sort order + $sql = "UPDATE mgw_workplace SET sort_order=sort_order-1 WHERE sort_order>$sort_order"; + if(!$conn->Execute($sql)) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__)); } *************** *** 122,126 **** $icons = getIconStrings(); ! $sql = "SELECT a.id, a.name, a.description, a.lu_date, b.username AS lu_user from mgw_workplace a LEFT JOIN mgw_users b ON a.lu_user = b.id"; if(!$res = $conn->Execute($sql)) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__)); while($row = $res->FetchRow()){ --- 174,178 ---- $icons = getIconStrings(); ! $sql = "SELECT a.id, a.name, a.description, a.sort_order, a.lu_date, b.username AS lu_user from mgw_workplace a LEFT JOIN mgw_users b ON a.lu_user = b.id ORDER BY a.sort_order"; if(!$res = $conn->Execute($sql)) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__)); while($row = $res->FetchRow()){ |