From d32ba6b5d9995560f750ee5e188e8c1a088baede Mon Sep 17 00:00:00 2001 From: Spiros Ioannou Date: Tue, 1 May 2012 16:09:55 +0300 Subject: [PATCH] new user editing --- itdb.php | 0 php/edituser.php | 199 ++++++++++++++++++++++++++++++++++++++++++++++ php/editusers.php | 103 ------------------------ php/listusers.php | 68 ++++++++++++++++ 4 files changed, 267 insertions(+), 103 deletions(-) create mode 100644 itdb.php create mode 100644 php/edituser.php delete mode 100644 php/editusers.php create mode 100644 php/listusers.php diff --git a/itdb.php b/itdb.php new file mode 100644 index 0000000..e69de29 diff --git a/php/edituser.php b/php/edituser.php new file mode 100644 index 0000000..074ece5 --- /dev/null +++ b/php/edituser.php @@ -0,0 +1,199 @@ +0) { + echo "User not deleted: Please reassign $nitems items first from this user
\n"; + echo "
Go back\n"; + exit; + } + else { + } + */ + deluser($delid,$dbh); //reassigns items to administrator + echo "\n"; + echo "Go here\n"; + exit; + +} + +if (isset($_POST['id'])) { //if we came from a post (save), update the user + $id=$_POST['id']; + $username=$_POST['username']; + $usertype=$_POST['usertype']; + + //don't accept empty fields + if (empty($_POST['username'])) { + echo "
Username field cannot be empty.
". + "Go back"; + exit; + } + + + if ($_POST['id']=="new") {//if we came from a post (save) the add user + $sql="INSERT into users (username , userdesc , pass, usertype) ". + " VALUES ('$username','$userdesc','$pass', '$usertype')"; + db_exec($dbh,$sql,0,0,$lastid); + $lastid=$dbh->lastInsertId(); + print "
Added user $lastid
"; + echo " "; //go to the new user + echo "\n"; + //$id=$lastid; + exit; + + }//new rack + else { + //check for duplicate username + $sql="SELECT count(id) AS count from users where username='{$_POST['username']}' AND id<>{$_POST['id']}"; + $sth1=db_execute($dbh,$sql); + $r1=$sth1->fetch(PDO::FETCH_ASSOC); + $sth1->closeCursor(); + $c=$r1['count']; + if ($c) { + echo "Not saved -- Username already exists"; + } + //else if ($_POST['id']==1 && $_POST['username']!="admin") { echo "Cannot change admin username"; } + else { + $sql="UPDATE users set ". + " username='".$_POST['username']."', ". + " userdesc='".$_POST['userdesc']."', ". + " pass='".$_POST['pass']."', ". + " usertype='".$_POST['usertype']."' ". + " WHERE id=$id"; + db_exec($dbh,$sql); + } + } +}//save pressed + +///////////////////////////// +//// display data + +if (!isset($_REQUEST['id'])) {echo "ERROR:ID not defined";exit;} +$id=$_REQUEST['id']; + +//$sql="SELECT * FROM racks where racks.id='$id'"; +$sql="SELECT * from users where users.id='$id'"; +$sth=db_execute($dbh,$sql); +$r=$sth->fetch(PDO::FETCH_ASSOC); + +if (($id !="new") && (count($r)<2)) {echo "ERROR: non-existent ID
($sql)";exit;} + +echo "\n
\n"; + +if ($id=="new") + echo "\n

".t("Add User")."

\n"; +else + echo "\n

".t("Edit User")." ($id)"."

\n"; + +?> + + +
+

+

.

+
    +
  1. +
+
+ + + + + + + + + + + + + + +
+ + + + + + + + "; + ?> + + + + + + + + +

User Properties

ID:
:
+
: +
: +
:
+
    +
  • +
  • 1
  • +
+
+
+
+ fetchAll(PDO::FETCH_ASSOC); + $nitems=count($ri); + $institems=""; + for ($i=0;$i<$nitems;$i++) { + $x=($i+1).": ".$ri[$i]['txt']; + if ($i%2) $bcolor="#D9E3F6"; else $bcolor="#ffffff"; + $institems.="\t
". + "$x
\n"; + } + echo $institems; + } + ?> +
+ +
+ +". + "".t("Delete"). "\n"; +?> + +
+ + + + +
+ + + diff --git a/php/editusers.php b/php/editusers.php deleted file mode 100644 index 388f87a..0000000 --- a/php/editusers.php +++ /dev/null @@ -1,103 +0,0 @@ - -"; print_r($_GET); print_r($_POST); - - -$formvars=array("id", "username","userdesc","pass"); - -//if came here from a form post, update db with new values -if (isset($_POST['username'])) { - $nrows=count($_POST['id']); //number of rows - - for ($rn=0;$rn<$nrows;$rn++) { - $id=$_POST['id'][$rn]; - if (($id == "new") && (strlen($_POST['username'][$rn])>1) ) {//new item -- insert - $sql="INSERT into users ". - "(username,userdesc,pass, usertype) ". - " values (". - "'".($_POST['username'][$rn])."',". - "'".($_POST['userdesc'][$rn])."',". - "'".($_POST['pass'][$rn])."',". - "'".($_POST['usertype'][$rn])."')"; - } - elseif ($id!="new"){ //existing item -- update - $sql="UPDATE users set ". - " username='".($_POST['username'][$rn])."', ". - " userdesc='".($_POST['userdesc'][$rn])."', ". - " pass='".($_POST['pass'][$rn])."', ". - " usertype='".($_POST['usertype'][$rn])."' ". - " WHERE id=$id"; - } - else {continue;} - - //echo "$rn $sql
"; - db_exec($dbh,$sql); - }//for -} //if - -$sql="select * from users order by username"; -$sth=db_execute($dbh,$sql); -?> - -
-

- - - - - - - - - - - -fetch(PDO::FETCH_ASSOC)) { - $i++; - if ($r['usertype']==0) - {$s0="selected"; $s1="";} - else - {$s1="selected"; $s0="";} - echo "\n\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo ""; - echo "\n\n"; -} - -?> - - - - - - - - - -
1
"; - echo "
-
1
-
- - diff --git a/php/listusers.php b/php/listusers.php new file mode 100644 index 0000000..fed9fdb --- /dev/null +++ b/php/listusers.php @@ -0,0 +1,68 @@ + + + +

+

+ + + + + + + + + + + + + + +fetch(PDO::FETCH_ASSOC)) { + $i++; + $itemcount=countitemsofuser($r['id']); + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; +} +?> + + +
{$r['id']}{$r['username']}{$r['userdesc']}{$usertype[$r['usertype']]}$itemcount
+ + + +