| [ PHPXref.com ] | [ Generated: Sun Jul 20 19:05:01 2008 ] | [ OneOrZero 1.6.3 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * file: tcreate.php 5 * 6 * This file contains the frontend for creating a new ticket. Provides error checking and also 7 * accesses the database to insert the information. 8 * 9 /*************************************************************************** 10 * This program is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU General Public 12 * License as published by the Free Software Foundation; either 13 * version 2.1 of the License, or (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 * General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public 21 * License along with This program; if not, write to: 22 * Free Software Foundation, Inc. 23 * 59 Temple Place 24 * Suite 330 25 * Boston, MA 02111-1307 USA 26 * 27 * Copyright 2005 One or Zero 28 * info@oneorzero.com 29 * http://www.oneorzero.com 30 * Developers: OneOrZero Team / Contributors: OneOrZero Community 31 ****************************************************************************/ 32 33 require_once "../common/common.php"; 34 require_once "../common/init_server_settings.php"; 35 require_once "../common/$database.class.php"; 36 require_once "../common/init_ooz.php"; 37 38 $language = getLanguage($_SESSION[user]); 39 if ($language == '') 40 require_once "../lang/$default_language.lang.php"; 41 else 42 require_once "../lang/$language.lang.php"; 43 44 require_once "../common/login.php"; 45 46 ############################################ 47 /* AUTOFILL 48 * Just in case we need, lets start storing 49 * the GET vars in the session so we can 50 * keep track of whats happening 51 */ 52 53 // if we hit tcreate without any get vars set 54 // it's pretty obvious that we are creating 55 // a new task so wax these vars so they aren't 56 // persistent. 57 58 59 //fleshout the vars from the query_string 60 61 list($garbage, $qvars) = split('&',$_SERVER[QUERY_STRING]); 62 63 //make sure we whack the vars but NOT if we are posting. 64 if (!isset($_POST['create'])){ 65 if ($qvars == "" || isset($_POST['reset'])){ 66 //reset all the autofill session vars 67 unsetautofill(); 68 } 69 } 70 // suport group 71 if ($_GET[sg] != ""){ 72 $_SESSION[autofill_sg] = urldecode($_GET[sg]); 73 } 74 // supporter 75 if ($_GET[supp] != ""){ 76 $_SESSION[autofill_supp] = urldecode($_GET[supp]); 77 } 78 //default the supporter on the ticket to support pool if 79 //no group has been selected 80 if ($_GET[supp] == "" && $_SESSION[autofill_supp] ==""){ 81 $_SESSION[autofill_supp] = 1; 82 } 83 // username 84 if ($_GET[usern] != ""){ 85 $_SESSION[autofill_user] = urldecode($_GET[usern]); 86 } 87 // priority 88 if ($_GET[pri] != ""){ 89 $_SESSION[autofill_pri] = urldecode($_GET[pri]); 90 } 91 // status 92 if ($_GET[status] != ""){ 93 $_SESSION[autofill_status] = urldecode($_GET[status]); 94 } 95 // platform 96 if ($_GET[platform] != ""){ 97 $_SESSION[autofill_platform] = urldecode($_GET[platform]); 98 } 99 // platform 100 if ($_GET[category] != ""){ 101 $_SESSION[autofill_category] = urldecode($_GET[category]); 102 } 103 // short description 104 if ($_GET[short] != ""){ 105 $_SESSION[autofill_short] = urldecode($_GET[short]); 106 } 107 // description 108 if ($_GET[description] != ""){ 109 $_SESSION[autofill_desc] = urldecode($_GET[description]); 110 } 111 112 if ($enable_ulist == 'Off') { 113 //prevent JS resetting user-keyed values if autofill not used 114 if (isset($_GET[email])) 115 $_SESSION[autofill_email] = $_GET[email]; 116 if (isset($_GET[office])) 117 $_SESSION[autofill_office] = $_GET[office]; 118 if (isset($_GET[phone])) 119 $_SESSION[autofill_phone] = $_GET[phone]; 120 } 121 122 //Build out autofill user variables if using autofill 123 if (isset($_SESSION[autofill_user]) && $enable_ulist != 'Off'){ 124 // first go SNAG the users record based on the current value of the user pull down 125 $autosql = "select * from $users_table where user_name = '$_SESSION[autofill_user]'"; 126 $autoresult = $db->query($autosql); 127 $autorow = $db->fetch_array($autoresult); 128 //we got it... so set some vars starting with email 129 $autoemail = $autorow[email]; 130 //office 131 $autooffice = $autorow[office]; 132 //phone 133 $autophone = $autorow[phone]; 134 } 135 136 ############################################################################## 137 138 if (isset($_POST[create])) { 139 //make sure our short and description are set - short desc must be linkable 140 $_SESSION[autofill_short] = strip_tags(trim(urldecode($_POST[shortdesc]))); 141 $_SESSION[autofill_desc] = urldecode($_POST[description]); 142 // after all error checking...insert into the database. 143 $time = time(); 144 $name = getUserInfo($_SESSION[autofill_supp]); 145 $name = $name['user_name']; 146 147 if ($_SESSION[autofill_sg] == '' || $_SESSION[autofill_pri] == '' || $_SESSION[autofill_user] == '' || $_SESSION[autofill_short] == '' || $_SESSION[autofill_desc] == '') { 148 $url = (" index.php?t=terr");; 149 echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; 150 exit; 151 } 152 153 if ($_SESSION[autofill_short] == '') { 154 $_SESSION[autofill_short] = "$lang_nodesc"; 155 } 156 if ($_SESSION[autofill_sg] == '') { 157 $_SESSION[autofill_sg] = 1; 158 } 159 160 // $username = user name of the user (not the supporter) 161 $short = stripScripts($_SESSION[autofill_short]); 162 $description = stripScripts($_SESSION[autofill_desc]); 163 $sql = "insert into $tickets_table values(NULL, '$time', '$_SESSION[autofill_sg]', '$name', '$_SESSION[autofill_supp]', '$_SESSION[autofill_pri]', '$_SESSION[autofill_status]', 164 '$_SESSION[autofill_user]', '$_POST[email]', '$_POST[office]', '$_POST[phone]', '$_SESSION[autofill_category]', '$_SESSION[autofill_platform]', '$short', '$description', NULL, 0, '$time')"; 165 $db->query($sql); 166 $tid = $db->insert_id(); 167 168 // // grab the id number of the ticket so we can create the created by in the update log. 169 // $sql = "SELECT id from $tickets_table where create_date='$time' and user='$_SESSION[autofill_user]' and short='$_SESSION[autofill_short]' and description='$_POST[description]'"; 170 // $result = $db->query($sql); 171 // $row = $db->fetch_array($result); 172 // $id = $row[0]; 173 // update the log so it shows who created the ticket now. 174 $msg = "<i>\$lang_taskcreatedby $_SESSION[user]</i>"; 175 $log = updateLog($tid, $msg); 176 $sql = "update $tickets_table set update_log='$log' where id=$tid"; 177 $db->query($sql); 178 // finally, to keep track of time stuff: 179 180 if ($status != getRStatus(getLowestRank($tstatus_table))) { 181 $time = $time + 1; //add one just so the response time isn't 0. 182 $sql = "INSERT into $time_table (ticket_id, supporter_id, opened_date) values ('$tid', '$_SESSION[autofill_supp]', $time)"; 183 $db->query($sql); 184 } 185 // insert the file into the database if it exists. 186 // Modified by Adam Hall to allow attachment file upload support 187 if ($enable_tattachments == 'On' && $_FILES['SelectedFile']['name'] != '' && $_FILES['SelectedFile']['name'] != 'none') { 188 //Upload file and return new file name 189 $mtime = explode(" ", microtime()); 190 $mtime = $mtime[1].substr($mtime[0],5,3); 191 $file_name = uploadAttachment($max_attachment_size, 'SelectedFile',$mtime); 192 $file_type = $_FILES['SelectedFile']['type']; 193 $file_size = $_FILES['SelectedFile']['size']; 194 $sql = "INSERT into $attachments_table VALUES (NULL, NULL, $tid, '$file_name', '$file_upload_directory', '$file_type', '$file_size', NULL, 0, '$_SESSION[user]', $time)"; 195 $db->query($sql); //insert all info about the attachment into the database. 196 $file_id = $db->insert_id(); 197 198 // $attachment = addslashes(fread(fopen($the_file, "rb"), filesize($the_file))); 199 // if ($the_file_type == "application/x-gzip-compressed") { 200 // $attachment = base64_decode($attachment); 201 // } 202 // 203 // $query = "INSERT into $attachments_table VALUES(NULL, NULL, $id, '$the_file_name', '$the_file_type', '$the_file_size', '$attachment', 0, '$logged_in_user', $time)"; 204 // $db->query($query); //insert all info about the attachment into the database. 205 // $file_id = $db->insert_id(); 206 207 $attachsize = $file_size; 208 if ($attachsize >= 1073741824) { 209 $attachsize = round($attachsize / 1073741824 * 100) / 100 . "gb"; 210 } elseif ($attachsize >= 1048576) { 211 $attachsize = round($attachsize / 1048576 * 100) / 100 . "mb"; 212 } elseif ($attachsize >= 1024) { 213 $attachsize = round($attachsize / 1024 * 100) / 100 . "kb"; 214 } else { 215 $attachsize = $attachsize . "b"; 216 } 217 // update the update log 218 $msg = "\$lang_fileattached : " . $_FILES['SelectedFile']['name'] . " ( $attachsize )"; 219 $log = updateLog($tid, $msg); 220 $sql = "update $tickets_table set update_log='$log' where id=$tid"; 221 $db->query($sql); 222 223 } 224 // if the pager gateway is enabled...send a page to the supporters of that group if the ticket is set above the default. 225 if ($enable_pager == 'On' && (getRank($_SESSION[autofill_pri], $tpriorities_table) <= $pager_rank_low)) { 226 sendGroupPage($_SESSION[autofill_sg], $_SESSION[autofill_user], $_SESSION[autofill_short], $_SESSION[autofill_pri], $tid); 227 } 228 229 unsetautofill(); 230 $url = (" $supporter_site_url/index.php?t=tsuc&id=$tid"); 231 echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; 232 exit; 233 //header("Location: $supporter_site_url/index.php"); 234 // 235 } else { 236 // task has not been committed yet, remove db escape slashes, next post will create them again 237 $_SESSION[autofill_short] = stripslashes($_SESSION[autofill_short]); 238 $_SESSION[autofill_desc] = stripslashes($_SESSION[autofill_desc]); 239 240 echo "<form action=index.php?t=tcre name=tcreate method=post enctype=\"multipart/form-data\">"; 241 ?> 242 243 <script language="JavaScript"> 244 <!-- 245 function refresh_uname() 246 { 247 var sURL = "index.php?t=tcre&usern="+escape(document.tcreate.username.value); 248 window.location.href = sURL; 249 } 250 function refresh_email() 251 { 252 var sURL = "index.php?t=tcre&email="+escape(document.tcreate.email.value); 253 window.location.href = sURL; 254 } 255 function refresh_office() 256 { 257 var sURL = "index.php?t=tcre&office="+escape(document.tcreate.office.value); 258 window.location.href = sURL; 259 } 260 function refresh_phone() 261 { 262 var sURL = "index.php?t=tcre&phone="+escape(document.tcreate.phone.value); 263 window.location.href = sURL; 264 } 265 function refresh_short() 266 { 267 var sURL = "index.php?t=tcre&short="+escape(document.tcreate.shortdesc.value); 268 window.location.href = sURL; 269 } 270 function refresh_desc() 271 { 272 var sURL = "index.php?t=tcre&description="+escape(document.tcreate.description.value); 273 window.location.href = sURL; 274 } 275 function MM_jumpMenu(targ,selObj,restore){ //v3.0 276 eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); 277 if (restore) selObj.selectedIndex=0; 278 } 279 //--></script> 280 281 <?php 282 createTicketHeader("$lang_create $lang_ticket"); 283 createSupporterInfo(); 284 createUserInfo(); 285 createTicketInfo('tcre'); 286 287 echo "<center>"; 288 echo "<input type=submit name=create value=\"$lang_create $lang_ticket\">"; 289 echo " "; 290 echo "<input type=submit name=reset value=$lang_reset>"; 291 echo "<input type=hidden name=sg value=" . $_GET[sg] . ">"; 292 echo "</form>"; 293 echo "</form>"; 294 echo "</center>"; 295 // most people will tab between the fields. 296 // with the js reload it faults the tab order so lets just 297 // assume and dump the cursor into the next field depending on what was the last 298 // modified. It's down here to override another set.focus 299 // that was previously set. and the field gets built in createTicketInfo. 300 // this also handles from the long description to the create button. 301 // Some fields are dependant on if the user is manually keyeing data 302 if ($enable_ulist == 'Off') { 303 if (ereg('usern=', $qvars)) 304 print '<script>document.tcreate.email.focus();</script>'; 305 if (ereg('email=', $qvars)) 306 print '<script>document.tcreate.office.focus();</script>'; 307 if (ereg('office=', $qvars)) 308 print '<script>document.tcreate.phone.focus();</script>'; 309 if (ereg('phone=', $qvars)) 310 print '<script>document.tcreate.platform.focus();</script>'; 311 } 312 else { 313 if (ereg('usern=', $qvars)) 314 print '<script>document.tcreate.platform.focus();</script>'; 315 } 316 if (ereg('platform=', $qvars)) 317 print '<script>document.tcreate.category.focus();</script>'; 318 if (ereg('category=', $qvars)) 319 print '<script>document.tcreate.shortdesc.focus();</script>'; 320 if (ereg('short=', $qvars)) 321 print '<script>document.tcreate.description.focus();</script>'; 322 if (ereg('description=', $qvars)) 323 print '<script>document.tcreate.create.focus();</script>'; 324 } 325 326 function createTicketHeader($msg) 327 { 328 startTable($msg, "center"); 329 endTable(); 330 } 331 332 function createSupporterInfo() 333 { 334 global $lang_supporterinfo, $lang_priority, $lang_status, $lang_Supporter, $lang_supportergroup; 335 336 if ($_SESSION[autofill_sg] == '') 337 338 $_SESSION[autofill_sg] = getDefaultSupporterGroupID(); 339 340 startTable("$lang_supporterinfo", "left", 100, 4); 341 342 echo '<tr> 343 <td width=27% class=back2 align=right>' . $lang_supportergroup . ':</td> 344 <td class=back width=20%> 345 <select name=group onChange="MM_jumpMenu(\'parent\', this, 0)">'; 346 createGroupMenu(0); 347 echo '</select> 348 </td> 349 <td class=back2 align=right width=100>' . $lang_Supporter . ': </td> 350 <td class=back align=left> 351 <select name=supporter_id onChange="MM_jumpMenu(\'parent\', this, 0)">'; 352 createSupporterMenu($_SESSION[autofill_sg]); 353 echo '</select> 354 </td> 355 </tr><tr> 356 <td width=27% class=back2 align=right>' . $lang_ticket . ' ' . $lang_priority . ':</td> 357 <td class=back> 358 <select name=priority onChange="MM_jumpMenu(\'parent\', this, 0)">'; 359 createPriorityMenu("tcre"); 360 echo '</select> 361 </td> 362 <td class=back2 align=right width=100>' . $lang_ticket . ' ' . $lang_status . ':</td> 363 <td class=back> 364 <select name=status onChange="MM_jumpMenu(\'parent\', this, 0)">'; 365 createStatusMenu(); 366 echo '</select> 367 </td> 368 </tr>'; 369 endTable(); 370 } 371 372 373 374 function createSupporterMenu($group_id) 375 { 376 global $users_table, $db,$table_prefix; 377 378 if ($group_id == '' || !isset($group_id) || $group_id == 1) { 379 $sql = "select id,user_name from $users_table where supporter=1 order by user_name asc"; 380 $table = $users_table; 381 } else { 382 $table = $table_prefix."sgroup" . $group_id; 383 $sql = "select user_id,user_name from $table order by user_name asc"; 384 } 385 386 $result = $db->query($sql); 387 388 while ($row = $db->fetch_array($result)) { 389 390 //just in case it doesn't get set by the initial 391 //users data set it to the default. 392 if ($_SESSION[autofill_supp] == ""){ 393 $_SESSION[autofill_supp] = $row[0]; 394 } 395 396 echo "<option value=index.php?t=tcre&supp=".urlencode($row[0]).""; 397 if (!strcasecmp($_SESSION[user], $row[1])){ 398 // echo " selected"; 399 //default the supporter. 400 if ($_SESSION[autofill_supp] == ""){ 401 $_SESSION[autofill_supp] = $row[0]; 402 } 403 } 404 if ($_POST[supporter_id] == $row[0] || $_SESSION[autofill_supp] == $row[0]){ 405 echo " selected"; 406 } 407 echo "> $row[1] </option>"; 408 } 409 } 410 411 function createUserInfo() 412 { 413 global $lang_userinfo, $lang_user, $lang_email, $lang_office; 414 global $lang_phoneext, $enable_ulist, $autoemail, $autooffice, $autophone; 415 startTable("$lang_userinfo", "left", 100, 4); 416 417 if ($enable_ulist != 'Off'){ 418 echo '<tr> 419 <td width=27% class=back2 align=right>' . $lang_user . ':</td> 420 <td class=back colspan=3>'; 421 422 echo '<select name=username onChange="MM_jumpMenu(\'parent\', this, 0)">'; 423 createUsersMenu(); 424 echo '</select>'; 425 echo '</td><tr> 426 <td class=back2 align=right width=27%>' . $lang_email . ': </td> 427 <td class=back align=left> 428 <input type=text name=email value = "'.$autoemail.'"> 429 </td> 430 <td class=back2 align=right>' . $lang_phoneext . ':</td> 431 <td class=back> 432 <input type=text name=phone value = "'.$autophone.'"> 433 </td></tr> 434 <tr> 435 <td width=27% class=back2 align=right>' . $lang_office . ':</td> 436 <td class=back colspan = 3> 437 <input type=text name=office value = "'.$autooffice.'"> 438 </td> 439 '; 440 }else{ 441 echo ' <tr> 442 <td width=27% class=back2 align=right>' . $lang_username . ':</td> 443 <td class=back width=20%>'; 444 echo ' <input type=text size=16 name=username value = "'.$_SESSION[autofill_user].'" onChange="refresh_uname()">'; 445 echo ' </td> 446 <td class=back2 align=right width=100>' . $lang_email . ': </td> 447 <td class=back align=left> 448 <input type=text name=email value = "'.$_SESSION[autofill_email].'" onChange="refresh_email()">'; 449 echo ' </td> 450 </tr> 451 <tr> 452 <td width=27% class=back2 align=right>' . $lang_office . ':</td> 453 <td class=back> 454 <input type=text size=16 name=office value = "'.$_SESSION[autofill_office].'" onChange="refresh_office()">'; 455 echo ' </td> 456 <td class=back2 align=right width=100>' . $lang_phoneext . ':</td> 457 <td class=back> 458 <input type=text name=phone value = "'.$_SESSION[autofill_phone].'" onChange="refresh_phone()">'; 459 echo ' </td>'; 460 } 461 endTable(); 462 } 463 464 465 function sendGroupPage($sg, $user_name, $short, $priority, $tid) 466 { 467 global $users_table, $admin_email, $helpdesk_name, $enable_smtp, $db; 468 global $table_prefix, $templates_table, $tickets_table, $lang_ticket, $lang_from, $lang_created, $lang_taskcreatedby, $supporter_site_url, $lang_shortdesc, $lang_priority; 469 470 $sql = "SELECT * from $tickets_table where id=$tid"; 471 $result = $db->query($sql); 472 $ticket = $db->fetch_array($result); //setup the ticket array so all variables are available. 473 // we have the groupid (sg), the username, short description. 474 // get the list of supporters to page. 475 if ($sg == 1) 476 $sql = "SELECT pager_email from $users_table"; 477 else 478 $sql = "select pager_email from $users_table, ".$table_prefix."sgroup" . $sg . " where $users_table.user_name=".$table_prefix."sgroup" . $sg . ".user_name"; 479 480 $result = $db->query($sql); 481 482 while ($row = $db->fetch_array($result)) { 483 // create the header list for the to address in the email. 484 if ($row[pager_email] != '') { 485 if ($list != 1) { 486 $to_list = $row[pager_email]; 487 $list = 1; 488 } else { 489 $to_list .= ", " . $row[pager_email]; 490 $list = 1; 491 } 492 } 493 } 494 495 $sql = "SELECT template from $templates_table where name='email_group_page'"; 496 $result = $db->query($sql); 497 $template = $db->fetch_array($result); 498 $template = str_replace("\\'", "'", $template[0]); 499 eval("\$email_msg = \"$template\";"); 500 501 if ($to_list != ''){ //handle case where no pager users have email addresses setup 502 sendEmail($to_list, $admin_email, $email_msg, "$lang_ticket $tid"); 503 } 504 } 505 506 507 508 ?>