| [ PHPXref.com ] | [ Generated: Sun Jul 20 20:44:36 2008 ] | [ Time Sheets 1.19 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 3 //define ("PB_CRYPT_LINKS" , "1"); 4 5 function DoEvents($this) { 6 global $_CONF , $_TSM; 7 8 $_TSM["MENU"] = ""; 9 10 //checking if user is logged in 11 if (!$_SESSION["minibase"]["user"]) { 12 13 if ($_SERVER["REQUEST_METHOD"] == "POST") { 14 15 //autentificate 16 $user = $this->db->QFetchArray("select * from {$this->tables[users]} where `user_login` = '{$_POST[user]}' AND `user_password` = '{$_POST[pass]}'"); 17 18 if (is_array($user)) { 19 $_SESSION["minibase"]["user"] = 1; 20 $_SESSION["minibase"]["raw"] = $user; 21 22 //redirecing to viuw sites 23 header("Location: $_CONF[default_location]"); 24 exit; 25 } else 26 return $this->templates["login"]->blocks["Login"]->output; 27 28 } else 29 return $this->templates["login"]->blocks["Login"]->output; 30 } 31 if ($_SESSION["minibase"]["raw"]["user_level"] == 0) { 32 $_TSM["MENU"] = $this->templates["login"]->blocks["MenuAdmin"]->output; 33 } else { 34 $_TSM["MENU"] = $this->templates["login"]->blocks["MenuUser"]->output; 35 } 36 37 if (!$_POST["task_user"]) 38 $_POST["task_user"] = $_SESSION["minibase"]["user"]; 39 40 if($_SESSION["minibase"]["raw"]["user_level"] == 1) { 41 $_CONF["forms"]["adminpath"] = $_CONF["forms"]["userpath"]; 42 } 43 44 switch ($_GET["sub"]) { 45 case "logout": 46 unset($_SESSION["minibase"]["user"]); 47 header("Location: index.php"); 48 49 return $this->templates["login"]->EmptyVars(); 50 break; 51 52 case "export2": 53 54 $data = new CForm($_CONF["forms"]["admintemplate"],$this->db,$this->tables); 55 56 if ($_SERVER["REQUEST_METHOD"] == "GET") { 57 58 $values["values"]["period"] = $_GET["period"]; 59 $values["values"]["user"] = $_GET["user"]; 60 } 61 62 if ($_GET["action"] == "store") { 63 if (is_array($values = $data->Validate($_CONF["forms"]["adminpath"] . "export2.xml",$_POST))) { 64 65 return $data->Show($_CONF["forms"]["adminpath"] . "export2.xml", $values); 66 } else { 67 68 header("Content-Type: text/x-csv"); 69 header("Content-Disposition: inline; filename=user.csv"); 70 header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 71 header("Pragma: public"); 72 73 $time_types = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[cats]}"); 74 75 echo '"Date","Employee Name","Employee Number",'; 76 if (is_array($time_types)) { 77 foreach ($time_types as $key => $val) { 78 echo (strstr($val["cat_name"] , " ") ? '"' . $val["cat_name"] . '"' : $val["cat_name"]) . "," ; 79 $_types[$val["cat_id"]] = $val["cat_name"]; 80 } 81 } 82 echo '"Total Time"' . "\n"; 83 84 $user = $this->db->QFetchArray("SELECT * FROM {$this->tables[users]} WHERE user_id={$_POST[user]}"); 85 $period = $this->db->QFetchArray("SELECT * FROM {$this->tables[periods]} WHERE period_id='{$_POST[period]}'"); 86 if (is_array($period)) { 87 $sheets = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[time]} WHERE time_period={$period[period_id]} AND time_user={$user[user_id]}"); 88 89 90 if (is_array($sheets)) { 91 foreach ($sheets as $key => $val) { 92 if (is_array($_sheets[$val["time_date"]])) { 93 $_sheets[$val["time_date"]]["hours"][$val["time_cat"]] += $val["time_hours"]; 94 } else { 95 $_sheets[$val["time_date"]] = $val; 96 $_sheets[$val["time_date"]]["hours"][$val["time_cat"]] = $val["time_hours"]; 97 } 98 } 99 100 foreach ($_sheets as $key => $sheet) { 101 $_tmp_total = 0; 102 103 //okay, now we can generate the csv 104 echo "\"" . date("m/d/Y" , $sheet["time_date"]) . "\","; 105 echo (strstr($user["user_name"] , " ") ? '"' . $user["user_name"] . '"' : $user["user_name"]) . "," ; 106 echo "\"" . $user["user_number"] . "\"" . "," ; 107 108 if (is_array($_types)) { 109 foreach ($_types as $key => $val) { 110 111 echo (int) $sheet["hours"][$key] ."," ; 112 $_tmp_total += (int)$sheet["hours"][$key]; 113 $_total += (int)$sheet["hours"][$key]; 114 115 $totals["hours"][$key] += (int) $sheet["hours"][$key]; 116 } 117 118 echo (int)$_tmp_total; 119 } 120 121 122 echo "\n"; 123 124 } 125 126 if (is_array($_types)) { 127 128 echo "Totals,,,"; 129 130 foreach ($_types as $key => $val) { 131 132 echo (int) $totals["hours"][$key] ."," ; 133 } 134 135 echo (int)$_total; 136 } 137 138 139 } 140 141 142 } 143 144 145 die; 146 } 147 } else 148 return $data->Show($_CONF["forms"]["adminpath"] . "export2.xml", $values); 149 break; 150 151 152 case "export": 153 $data = new CForm($_CONF["forms"]["admintemplate"],$this->db,$this->tables); 154 155 if ($_SERVER["REQUEST_METHOD"] == "GET") { 156 157 $values["values"]["period"] = $_GET["period"]; 158 $values["values"]["user"] = $_GET["user"]; 159 } 160 161 if ($_GET["action"] == "store") { 162 if (is_array($values = $data->Validate($_CONF["forms"]["adminpath"] . "export.xml",$_POST))) { 163 164 return $data->Show($_CONF["forms"]["adminpath"] . "export.xml", $values); 165 } else { 166 167 header("Content-Type: text/x-csv"); 168 header("Content-Disposition: inline; filename=period.csv"); 169 header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 170 header("Pragma: public"); 171 172 $time_types = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[cats]}"); 173 174 echo '"Pay Period","Employee Name","Employee Number",'; 175 if (is_array($time_types)) { 176 foreach ($time_types as $key => $val) { 177 echo (strstr($val["cat_name"] , " ") ? '"' . $val["cat_name"] . '"' : $val["cat_name"]) . "," ; 178 $_types[$val["cat_id"]] = $val["cat_name"]; 179 } 180 } 181 echo '"Total Time"' . "\n"; 182 183 $users = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[users]}"); 184 if (is_array($users)) { 185 foreach ($users as $key => $val) { 186 $_users[$val["user_id"]] = $val; 187 } 188 } 189 //read the period 190 $periods = $this->db->QFetchROwArray("SELECT * FROM {$this->tables[periods]}" . ( $_POST["period"] ? " WHERE period_id='{$_POST[period]}'" : "" )); 191 if (is_array($periods)) { 192 foreach ($periods as $key => $period) { 193 194 if (is_array($_users)) { 195 foreach ($_users as $_k => $user) { 196 if ((($_POST["user"] != "" ) && ($_POST["user"] == $_k)) || ( $_POST["user"] == 0)) { 197 $sheets = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[time]} WHERE time_period={$period[period_id]} AND time_user={$user[user_id]}"); 198 199 $_tmp_total = 0; 200 201 if (is_array($sheets)) { 202 //okay, now we can generate the csv 203 echo "\"" . date("m/d/Y" , $period["period_start"]) . " - " . date("m/d/Y" , $period["period_end"]) . "\","; 204 echo (strstr($user["user_name"] , " ") ? '"' . $user["user_name"] . '"' : $user["user_name"]) . "," ; 205 echo "\"" . $user["user_number"] . "\"" . "," ; 206 207 if (is_array($time_types)) { 208 foreach ($time_types as $key => $val) { 209 210 //read the sheets again 211 $_sheets = $this->db->QFetchArray("SELECT sum(time_hours) FROM {$this->tables[time]} WHERE time_period={$period[period_id]} AND time_user={$user[user_id]} AND time_cat='{$val[cat_id]}'"); 212 213 echo (int)$_sheets["sum(time_hours)"] ."," ; 214 $_tmp_total += (int)$_sheets["sum(time_hours)"]; 215 $_total += (int)$_sheets["sum(time_hours)"]; 216 } 217 218 echo (int)$_tmp_total; 219 } 220 221 222 echo "\n"; 223 224 } 225 } 226 } 227 } 228 } 229 } 230 die; 231 } 232 } else 233 return $data->Show($_CONF["forms"]["adminpath"] . "export.xml", $values); 234 break; 235 236 case "periods": 237 case "cats": 238 case "time": 239 240 if ($_SESSION["minibase"]["raw"]["user_level"] != 0) { 241 $_GET["user"] = $_SESSION["minibase"]["raw"]["user_id"]; 242 $_POST["user"] = $_SESSION["minibase"]["raw"]["user_id"]; 243 $_POST["time_user"] = $_SESSION["minibase"]["raw"]["user_id"]; 244 } 245 246 247 if (($_GET["sub"] == "time") && ( $_GET["action"] == "store")) { 248 249 //read the period to do the time check 250 $period = $this->db->QFetchArray("SELECT * FROM {$this->tables[periods]} WHERE period_id='{$_POST[time_period]}'"); 251 252 $time_date = mktime(1,1,1,$_POST["time_date_month"] , $_POST["time_date_day"] , $_POST["time_date_year"]); 253 254 if (($period["period_start"] > $time_date) || ($period["period_end"] < $time_date)) { 255 //ok, this guy tries to cheat me 256 $_POST["time_date"] = $time_date; 257 258 259 $file = "./forms/admin/time/add.xml"; 260 261 $data = new CForm($_CONF["forms"]["admintemplate"],$this->db,$this->tables); 262 263 $values["values"] = $_POST; 264 265 $values["error"] = "Selected time isn't in the corect period range: " . date("m.d.Y" , $period["period_start"]) . " - " . date("m.d.Y" , $period["period_end"]); 266 $values["errors"]["time_date"] = true; 267 return $data->Show($file, $values); 268 } 269 } 270 271 272 if (($_GET["sub"] == "expenses") && ($_GET["action"] == "store") && $_POST["expense_id"]){ 273 274 } 275 276 if ($_SESSION["minibase"]["raw"]["user_level"] != 0) { 277 } 278 279 if ($_SERVER["REQUEST_METHOD"] != "POST") { 280 $_POST["comment_user"] = $_SESSION["minibase"]["raw"]["user_id"]; 281 $_POST["comment_date"] = time(); 282 } 283 284 if (($_GET["sub"] == "periods") && ($_GET["action"] == "details")) { 285 $tmp = $this->db->QFetchRowArray("SELECT sum(time_hours) FROM {$this->tables[time]} WHERE time_period=" . (int)$_GET["period_id"]." " . ($_GET["user"] ? "AND time_user={$_GET[user]}" : "" )); 286 $total = $tmp[0]["sum(time_hours)"]; 287 288 $task = new CSQLAdmin("time" . ($_GET["user"] ? ".user" : "" ), $_CONF["forms"]["admintemplate"],$this->db,$this->tables , $extra); 289 290 if ($_SESSION["minibase"]["raw"]["user_level"] == 1) 291 $extra["details"]["fields"]["period_description"] .= $task->DoEvents(); 292 else 293 $extra["details"]["fields"]["user"] .= $task->DoEvents(); 294 295 296 297 } 298 299 $data = new CSQLAdmin($_GET["sub"], $_CONF["forms"]["admintemplate"],$this->db,$this->tables , $extra); 300 301 if (($_GET["sub"] == "periods") && ($_GET["action"] == "details")) { 302 $data->forms["forms"]["details"]["fields"]["report_title"]= array( 303 304 "type" => "subtitle", 305 "title" => "Totals (H: {$total})" 306 ); 307 308 //show all totals depending of time types 309 $types = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[cats]}"); 310 if (is_array($types)) { 311 foreach ($types as $key => $val) { 312 $tmp = $this->db->QFetchRowArray("SELECT sum(time_hours) FROM {$this->tables[time]} WHERE time_period=" . (int)$_GET["period_id"]." AND time_cat='{$val[cat_id]}' " . ($_GET["user"] ? "AND time_user={$_GET[user]}" : "" )); 313 $tmptotal = (int)$tmp[0]["sum(time_hours)"]; 314 315 316 $data->forms["forms"]["details"]["fields"]["report_total_" . $key]= array( 317 318 "type" => "text", 319 "title" => "" . $val["cat_name"] . "", 320 "forcevalue" => $tmptotal . " hours" 321 322 ); 323 324 } 325 } 326 327 328 $data->forms["forms"]["details"]["fields"]["report_total"]= array( 329 330 "type" => "text", 331 "title" => "Total Hours", 332 "forcevalue" => $total 333 334 ); 335 } 336 return $data->DoEvents("","",$_POST); 337 break; 338 339 case "users": 340 341 if ((!$_GET["action"])&&($_SESSION["minibase"]["raw"]["user_level"] != 0 )) { 342 $_GET["action"] = "details"; 343 } 344 345 if ($_SESSION["minibase"]["raw"]["user_level"] == 1) { 346 $_GET["user_id"] = $_SESSION["minibase"]["raw"]["user_id"]; 347 $_POST["user_id"] = $_SESSION["minibase"]["raw"]["user_id"]; 348 } 349 350 $data = new CSQLAdmin($_GET["sub"], $_CONF["forms"]["admintemplate"],$this->db,$this->tables); 351 return $data->DoEvents(); 352 break; 353 } 354 } 355 356 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |