[ PHPXref.com ] [ Generated: Sun Jul 20 16:24:58 2008 ] [ ackerTodo 3.8 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/src/includes/ -> cli.inc (source)

   1  <?php
   2  /* vim: set ts=4 sw=4 si:
   3  * ackerTodo - a web-based todo list manager which supports multiple users
   4  * Copyright (C) 2004-2005 Rob Hensley
   5  *
   6  * This program is free software; you can redistribute it and/or modify
   7  * it under the terms of the GNU General Public License as published by
   8  * the Free Software Foundation; either version 2 of the License, or (at
   9  * your option) any later version.
  10  *
  11  * This program is distributed in the hope that it will be useful, but
  12  * WITHOUT ANY WARRANTY; without even the implied warranty of
  13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14  * General Public License for more details.
  15  *
  16  * You should have received a copy of the GNU General Public License
  17  * along with this program; if not, write to the Free Software
  18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19  *
  20  * $Id: cli.inc,v 1.7 2005/06/09 02:15:55 zoidian Exp $
  21  */
  22  ?>
  23  <?php
  24  function list_users($how = NULL) {
  25      $result = db_query("SELECT * FROM users");
  26  
  27      echo "All Users\n";
  28      echo "=========\n\n";
  29      while($myrow = mysql_fetch_array($result)) {
  30          if($myrow['admin'] == 1) {
  31              $admin = "(Admin)";
  32          } else {
  33              $admin = "";
  34          }
  35  
  36          echo $i . ".) Login:  " . $myrow['login'] . " " . $admin . "\n";
  37  
  38          if($myrow['first'] || $myrow['last']) {
  39              echo "      Name:  " . $myrow['first'] . " " . $myrow['last'] . "\n";
  40          }
  41          
  42          if($myrow['email']) {
  43              echo "     Email:  " . $myrow['email'] . "\n";
  44          }
  45  
  46          echo "\n";
  47          $i++;
  48      }
  49  }
  50  
  51  function print_help() {
  52      echo "ackerTodo Rob Hensley <hensleyrob@nku.edu>\n";
  53      echo "Usage: php cmd.php <list_tasks|add_task|del_task\n";
  54      echo "                    list_users|add_user|del_user\n";
  55      echo "                    add_category|del_category>\n";
  56      echo "      list_tasks:  List your currently open tasks.\n";
  57      echo "        add_task:  Add a new task.\n";
  58      echo "        del_task:  Delete a task.\n";
  59      echo "      list_users:  List all of the users.\n";
  60      echo "        add_user:  Add a new user. (Admin Only)\n";
  61      echo "        del_user:  Delete a user. (Admin Only)\n";
  62      echo "    add_category:  Add a category.\n";
  63      echo "    del_category:  Delete a category.\n";
  64      echo "Example: php cmd.php list_tasks\n";
  65  }
  66  
  67  function list_tasks($login) {
  68      $i = 1;
  69      
  70      $result = db_query("SELECT * FROM tasks "
  71                        ."WHERE login='$login' "
  72                        ."AND completed='0'");
  73  
  74      echo "Currently Open Tasks\n";
  75      echo "====================\n\n";
  76      while($myrow = mysql_fetch_array($result)) {
  77          $date = format_date_simple($myrow['date']);
  78          echo $i . ".) Title:  " . $myrow['title'] . "\n";
  79          echo "     Date:  " . $date . "\n";
  80          echo "\n";
  81          $i++;
  82      }
  83  }
  84  
  85  function add_task($login) {
  86      $date = date("Ymd");
  87      $today = date("YmdHms");
  88  
  89      while(!$title) {
  90          echo "Title: ";
  91          $title = trim(fgets(STDIN));
  92      }
  93  
  94      echo "Due Date (".$date."): ";
  95      $temp_date = trim(fgets(STDIN));
  96      $temp_date = trim($temp_date);
  97      
  98      if(is_numeric($temp_date) && strlen($temp_date) == "8") {
  99          $date = $temp_date;
 100      }
 101  
 102      while(!$task) {
 103          echo "Task: ";
 104          $task = trim(fgets(STDIN));
 105      }
 106  
 107      echo "Priority (0-3): ";
 108      $priority = trim(fgets(STDIN));
 109      if($priority != "0" || $priority != "1" ||
 110          $priority != "2" || $priority != "3") {
 111          $priority = "0";
 112      }   
 113  
 114      echo "No Recurrece/Daily/Weekly/Monthly/Yearly/Open-Ended (N/d/w/m/y/o): ";
 115      $recurrence = trim(fgets(STDIN));
 116      if($recurrence == "d" || $recurrence == "D") {
 117          $recurrence = 1;
 118      } elseif($recurrence == "w" || $recurrence == "W") {
 119          $recurrence = 2;
 120      } elseif($recurrence == "m" || $recurrence == "M") {
 121          $recurrence = 3;
 122      } elseif($recurrence == "y" || $recurrence == "Y") {
 123          $recurrence = 5;
 124      } elseif($recurrence == "o" || $recurrence == "O") {
 125          $recurrence = 4;
 126      } else {
 127          $recurrence = 0;
 128      }
 129  
 130      $result = db_query("INSERT INTO tasks "
 131                        ."(login,creationdate,recurrence,title,task,"
 132                        ."date,assignedby,category,priority) "
 133                        ."VALUES ('$login','$today','$recurrence','$title',"
 134                        ."'$task','$date','$login','0','$priority')");
 135  
 136  //    if(!$result || mysql_num_rows($result) != 1) {
 137  //        echo "Failed To Add Task!\n";
 138  //        exit;
 139  //    }
 140  
 141      echo "Task Added Successfully!\n";
 142  }
 143  
 144  function del_task($login) {
 145      $result = db_query("SELECT * FROM tasks "
 146                        ."WHERE login='$login' "
 147                        ."ORDER by id");
 148      
 149      echo "All Tasks\n";
 150      echo "=========\n\n";
 151      while($myrow = mysql_fetch_array($result)) {
 152          echo $myrow['id'] . ".) Title:  " . $myrow['title'] . "\n";
 153      }
 154  
 155      while(!$delete) {
 156          echo "\nEnter the number of the task to delete: ";
 157          $delete = trim(fgets(STDIN));
 158      }
 159  
 160      $result = db_query("DELETE FROM tasks "
 161                        ."WHERE id='$delete'");
 162  
 163  //    if(!$result || mysql_num_rows($result) != 1) {
 164  //        echo "Failed To Delete Task!\n";
 165  //        exit;
 166  //    }
 167  
 168      echo "Task Deleted Successfully!\n";
 169  }
 170  
 171  function del_user($login) {
 172      while(!$delete) {
 173          echo "Enter the login name of the user to delete: ";
 174          $delete = trim(fgets(STDIN));
 175      }
 176  
 177      $result = db_query("DELETE FROM users "
 178                        ."WHERE login='$delete'");
 179  
 180  //    if(!$result || mysql_num_rows($result) != 1) {
 181  //          echo "Failed To Delete User!\n";
 182  //          exit;
 183  //    }
 184  
 185      echo "User Deleted Successfully!\n";
 186  }
 187  
 188  function add_category($login) {
 189      while(!$new_cat || $exists == 1) {
 190          if($exists == 1) {
 191              echo "Category already exists!\n";
 192          }
 193  
 194          echo "Category Name: ";
 195          $new_cat = trim(fgets(STDIN));
 196  
 197          $result = db_query("SELECT * FROM category "
 198                            ."WHERE login='$login' "
 199                            ."AND category='$new_cat'");
 200  
 201          if(mysql_num_rows($result) == 1) {
 202              $exists = 1;
 203          } else {
 204              $exists = 0;
 205          }
 206      }
 207  
 208      $result = db_query("INSERT INTO category "
 209                        ."(login,name)"
 210                        ."VALUES ('$login','$new_cat')");
 211  
 212  //    if(!$result || mysql_num_rows($result) != 1) {
 213  //          echo "Failed To Add Category!\n";
 214  //          exit;
 215  //    }
 216  
 217      echo "Category Added Successfully!\n";
 218  }
 219  
 220  function del_category($login) {
 221      while(!$delete) {
 222          echo "Enter the category name to delete: ";
 223          $delete = trim(fgets(STDIN));
 224      }
 225  
 226      $result = db_query("DELETE FROM category "
 227                        ."WHERE login='$login' "
 228                        ."AND name='$delete'");
 229  
 230  //    if(!$result || mysql_num_rows($result) != 1) {
 231  //          echo "Failed To Delete Category!\n";
 232  //          exit;
 233  //    }
 234  
 235      echo "Category Deleted Successfully!\n";
 236  }
 237  
 238  function list_categories($login) {
 239      $i = 1;
 240      
 241      $result = db_query("SELECT * FROM category "
 242                        ."WHERE login='$login'");
 243  
 244      echo "All Your Categories\n";
 245      echo "===================\n\n";
 246      while($myrow = mysql_fetch_array($result)) {
 247          echo $i . ".) " . $myrow['name'] . "\n";
 248          $i++;
 249      }
 250  
 251      echo "\n";
 252  }
 253  
 254  function add_user() {
 255      echo "New User Information\n";
 256      echo "====================\n";
 257  
 258      while(!$new_login || $exists == 1) {
 259          if($exists == 1) {
 260              echo "User already exists!\n";
 261          }
 262  
 263          echo "Login: ";
 264          $new_login = trim(fgets(STDIN));
 265  
 266          $result = db_query("SELECT * FROM users "
 267                            ."WHERE login='$new_login'");
 268  
 269          if(mysql_num_rows($result) == 1) {
 270              $exists = 1;
 271          } else {
 272              $exists = 0;
 273          }
 274      }
 275      
 276      echo "First Name: ";
 277      $new_first = trim(fgets(STDIN));
 278  
 279      echo "Last Name: ";
 280      $new_last = trim(fgets(STDIN));
 281  
 282      echo "E-Mail: ";
 283      $new_email = trim(fgets(STDIN));
 284  
 285      echo "AIM Screenname: ";
 286      $new_screenname = trim(fgets(STDIN));
 287  
 288      echo "Administrator (y/N): ";
 289      $new_admin = trim(fgets(STDIN));
 290      
 291      if($new_admin == "y" || $new_admin == "Y") {
 292          $new_admin = "1";
 293      } else {
 294          $new_admin = "0";
 295      }
 296      
 297      $i = 0;
 298      while(!$new_pass || !$new_pass_ver || $match == 0) {
 299          if($i > 0 && $match == 0) {
 300              echo "Passwords don't match!\n";
 301          }
 302  
 303          echo "Password: ";
 304          system("stty -echo");
 305          $new_pass = trim(fgets(STDIN));
 306          system("stty echo");
 307          echo "\n";
 308  
 309          echo "Verify Password: ";
 310          system("stty -echo");
 311          $new_pass_ver = trim(fgets(STDIN));
 312          system("stty echo");
 313          echo "\n";
 314  
 315          if($new_pass == $new_pass_ver) {
 316              $match = 1;
 317          } else {
 318              $match = 0;
 319          }
 320          
 321          $i++;
 322      }
 323  
 324      $result = db_query("INSERT INTO users "
 325                        ."(login,password,first,last,email,"
 326                        ."screenname,admin) "
 327                        ."VALUES ('$new_login','$new_pass',"
 328                        ."'$new_first','$new_last','$new_email',"
 329                        ."'$new_screenname','$new_admin')");
 330  
 331  //    if(!$result || mysql_num_rows($result) != 1) {
 332  //        echo "Failed To Add User!\n";
 333  //        exit;
 334  //    }
 335  
 336        echo "User Added Successfully!\n";
 337  }
 338  
 339  function login() {
 340      while(!$login) {
 341          echo "Login: ";
 342          $login = trim(fgets(STDIN));
 343      }
 344  
 345      echo "Password: ";
 346      system("stty -echo");
 347      $pass = trim(fgets(STDIN));
 348      system("stty echo");
 349      $enc_pass = md5($pass);
 350      echo "\n";
 351  
 352      $result = db_query("SELECT * FROM users "
 353                        ."WHERE login='$login' "
 354                        ."AND password='$enc_pass'");
 355  
 356      $myrow = mysql_fetch_array($result);
 357      $isadmin = $myrow['admin'];
 358  
 359      if(!$result || mysql_num_rows($result) != 1) {
 360          echo "Login Failed!\n";
 361          exit;
 362      }
 363  
 364      if($choice == "add_user" || $choice == "del_user") {
 365          if(!$isadmin == 1) {
 366              echo "You're Not An Admin!\n\n";
 367              exit;
 368          }
 369      }
 370  
 371      echo "Login Successful!\n\n";
 372      
 373      
 374      return $login;
 375  }
 376  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]