Файл: _rootadmin/_tickets.inc.php
Строк: 1031
<?
if ($uid) { print menu_admin_client($uid); }
if ($sub == "setrefresh" and intval($refreshtime) >= 0) {
SetSetting("tickets_refresh",intval($refreshtime));
$sub = "";
}
if ($sub == "delete" and $id) {
checkAdminAccess('ticketsDelete',1);
@mysql_query("delete from tickets where id='$id'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
@mysql_query("delete from tickets where parentid='$id'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
writeAdminLog("Удален тикет ID # $id");
print "Тикет успешно удален.<br><br>";
print "[ <a href=?do=tickets>перейти к списку тикетов</a> ]<BR><BR>";
}
if ($sub == "view" or $sub == "editreply" or $sub == "attach" or $sub == "unattach" or $sub == "reply" or $sub == "close" or $sub == "delmsg" or $sub == "wait" or $sub == "movedepartment" or $sub == "assignto") {
$id = preg_replace("/D/","",$id);
if (!$id) {print "<font color=red>Утерян идентификатор тикета.</font><br><br>";}
else {
if ($sub == "reply") {
checkAdminAccess('ticketsEdit',1);
if (!$message) { print "<font color=red>Не указано сообщение.</font><br><br>";}
else {
$admUser = GetAdminById($_SESSION["adminId"]);
if ($admUser->signature) {
$message = $message."rnrn".$admUser->signature;
}
$z=@mysql_query("select * from tickets where parentid='$id' and message='".addslashes($message)."'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
if (mysql_num_rows($z) > 0) {
$message="";
$sub = "view";
} else {
@mysql_query("update tickets set newforuser='1',status='open',sendadminsms='$sendadminsms' where id='$id'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
@mysql_query("insert into tickets (parentid,dt,message,adminname,adminId) values('$id',NOW(),'".addslashes($message)."','".$_SESSION["adminName"]."','".$_SESSION["adminId"]."')") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
$reply_id = @mysql_insert_id();
$attached = array();
for ($i=0; $i < count($_FILES['userfile']['name']); $i++) {
if ($_FILES['userfile']['name'][$i]) {
if ($_FILES['userfile']['name'][$i] != '' and $_FILES['userfile']['type'][$i] != '' and $_FILES['userfile']['tmp_name'][$i] != '') {
preg_match("/^(.+).([^.]+)$/ui",$_FILES['userfile']['name'][$i],$arr);
$filename = $arr[1]; $fileext = $arr[2];
$newFile = "ticket_".$reply_id."_".$filename.".".$fileext;
$file=$full_home_path."/_rootfiles/".$newFile;
if (!file_exists($file)) {
if (move_uploaded_file($_FILES['userfile']['tmp_name'][$i],$file)) {
@chmod($file, 0777);
$attached[] = "$newFile::$filename.$fileext";
print "Файл №".($i+1)." успешно загружен.<BR>";
} else {
print "Ошибка загрузки файла №".($i+1).".<BR>";
}
} else {
print "Ошибка загрузки файла №".($i+1)." - такой файл уже существует.<BR>";
}
}
}
}
if (@count($attached) > 0) {
$attached = @join(":x:",$attached);
@mysql_query("update tickets set attachedFiles='$attached' where id='$reply_id'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
} else {
$attached = "";
}
$ticket=GetTicketById($id);
$user = GetUserById($ticket->userid);
$pwd = generatePassword(25);
@mysql_query("update users set tempPassword='".crypt($pwd)."' where id='$user->id'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
$tpl=GetTpl('email_touser_ticket_reply',$user->lang);
$subj=$tpl[subject]; $template=$tpl[template];
if ($subj and $template) {
$company_name=GetSetting('company_name');
$company_url=GetSetting('company_url');
$support_email=GetSetting("support_email");
$support_url=GetSetting('support_url');
$subj = str_replace('{id}',$id,$subj);
$template = str_replace('{company_name}',$company_name,$template);
$template = str_replace('{company_url}',$company_url,$template);
$template = str_replace('{support_url}',$support_url,$template);
$template = str_replace('{subject}',$ticket->subject,$template);
$template = str_replace('{message}',$message,$template);
$template = str_replace('{id}',$id,$template);
$template = str_replace('{link}',$full_www_path."billing.php?do=tickets&sub=view&id=$id&login=$user->login&pass=$pwd",$template);
WriteMailLog($subj,$template,$user->id);
sendmail($user->email,$company_name,$support_email,$subj,$template,'','',$tpl[type]);
sendmail($user->email2,$company_name,$support_email,$subj,$template,'','',$tpl[type]);
}
if ($ticket->sendsms and GetSetting("smsGateway") and GetSetting("smsUserTicketReply")) {
$tpl=GetTpl('email_touser_ticket_reply_sms',$user->lang);
$template=$tpl[template];
if ($template and $user->mobile) {
$company_name=GetSetting('company_name');
$company_url=GetSetting('company_url');
$support_email=GetSetting("support_email");
$support_url=GetSetting('support_url');
$template = str_replace('{company_name}',$company_name,$template);
$template = str_replace('{company_url}',$company_url,$template);
$template = str_replace('{support_url}',$support_url,$template);
$template = str_replace('{subject}',$ticket->subject,$template);
$template = str_replace('{message}',$message,$template);
$template = str_replace('{id}',$id,$template);
$template = str_replace('{link}',$full_www_path."billing.php?do=tickets&sub=view&id=$id&login=$user->login&pass=$pwd",$template);
sendSMS($user->id,'',$template);
}
}
$message="";
writeAdminLog("Добавлен ответ в тикет ID # $id");
print "Сообщение успешно добавлено.<br><br>";
$sub = "view";
# print "[ <a href=?do=tickets&sub=view&id=$id>вернуться в тикет</a> ] [ <a href=?do=tickets>перейти к списку тикетов</a> ]<BR><BR>";
}
}
}
if ($sub == "editreply") {
checkAdminAccess('ticketsEdit',1);
if (!$message) { print "<font color=red>Не указано сообщение.</font><br><br>";}
else {
@mysql_query("update tickets set sendadminsms='$sendadminsms' where id='$id'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
@mysql_query("update tickets set dt=NOW(),message='".addslashes($message)."' where id='$msgid'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
writeAdminLog("Изменен ответ в тикете ID # $id");
print "Ответ успешно изменен.<BR><br>";
$sub = "view";
$sub2 = "";
$msgid = "";
$message = "";
$sendadminsms = "";
}
}
if ($sub == "delmsg" and $id and $msgid) {
checkAdminAccess('ticketsEdit',1);
@mysql_query("delete from tickets where parentid='$id' and id='$msgid'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
writeAdminLog("Удалено сообщение в тикете ID # $id");
$sub = "view";
}
if ($sub == "close" and $id) {
checkAdminAccess('ticketsEdit',1);
$z = @mysql_query("select * from tickets where status='closed' and id='$id'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
if (mysql_num_rows($z) == 0) {
$user = GetUserById($uid);
$varLng = LoadLanguageToVariable($user->lang);
@mysql_query("update tickets set status='closed' where id='$id'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
@mysql_query("insert into tickets (parentid,dt,message) values('$id',NOW(),'".$varLng[TicketsClosedBySupport]."')") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
writeAdminLog("Закрыт тикет ID # $id");
print "Тикет успешно закрыт.<br><br>";
print "[ <a href=?do=tickets&sub=view&id=$id>вернуться в тикет</a> ] [ <a href=?do=tickets>перейти к списку тикетов</a> ]<BR><BR>";
} else {
$sub = "view";
}
}
if ($sub == "wait" and $id) {
checkAdminAccess('ticketsEdit',1);
$z = @mysql_query("select * from tickets where status='wait' and id='$id'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
if (mysql_num_rows($z) == 0) {
@mysql_query("update tickets set status='wait' where id='$id'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
writeAdminLog("Тикет ID # $id переведен в ожидание");
print "Тикет успешно переведен в ожидание.<br><br>";
print "[ <a href=?do=tickets&sub=view&id=$id>вернуться в тикет</a> ] [ <a href=?do=tickets>перейти к списку тикетов</a> ]<BR><BR>";
} else {
$sub = "view";
}
}
if ($sub == "attach" and $id) {
checkAdminAccess('ticketsEdit',1);
@mysql_query("update tickets set attached='1' where id='$id'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
writeAdminLog("Прикреплен тикет ID # $id");
print "Тикет успешно прикреплен.<br><br>";
print "[ <a href=?do=tickets&sub=view&id=$id>вернуться в тикет</a> ] [ <a href=?do=tickets>перейти к списку тикетов</a> ]<BR><BR>";
}
if ($sub == "movedepartment" and $id and $department) {
checkAdminAccess('ticketsEdit',1);
$ticket=GetTicketById($id);
$group = GetAdminGroupById($department);
$priority = $ticket->priority;
@mysql_query("update tickets set department='$department' where id='$id'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
$support_email=GetSetting("support_email");
$subject_msg = "[#$ticket->id] Ticket move [важность ".$_priority[$priority]."]";
$message = "Тикет "".htmlDecode($ticket->subject)."" (ID # $ticket->id) перенесен администрацией в отдел $group->namennПерейти к тикету можно по ссылке: ".$full_www_path.$admin_script."?do=tickets&sub=view&id=$ticket->idnnСообщение:nn".htmlDecode($ticket->message);
$admEmails=GetAdminEmailsWhereTrueParam("sendticket",$department);
if (count($admEmails) > 0) {
WriteMailLog($subject_msg,$message);
}
while (list($i,$em) = @each($admEmails)) {
sendmail($em,'',$support_email,$subject_msg,$message);
}
if (GetSetting("smsGateway")) {
$smsmsg = "[".$_prioritysms[$priority]."] Ticket move #$ticketid: $subject";
$admIds=GetAdminIdsWhereTrueParam("sms_sendticketnew",$department);
while (list($i,$aid) = @each($admIds)) {
$smsAdmin=GetAdminById($aid);
if ($smsAdmin->mobile) {
sendSMS('',$aid,$smsmsg);
}
}
}
writeAdminLog("Тикет ID # $id перенесен в отдел $group->name");
print "Тикет успешно перенесен в отдел $group->name.<br><br>";
print "[ <a href=?do=tickets&sub=view&id=$id>вернуться в тикет</a> ] [ <a href=?do=tickets>перейти к списку тикетов</a> ]<BR><BR>";
}
if ($sub == "assignto" and $id and $adminid) {
checkAdminAccess('ticketsEdit',1);
$ticket=GetTicketById($id);
$admin = GetAdminById($adminid);
$priority = $ticket->priority;
@mysql_query("update tickets set assignedto='$admin->id' where id='$id'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
$support_email=GetSetting("support_email");
$subject_msg = "[#$ticket->id] Ticket assign [важность ".$_priority[$priority]."]";
$message = "Тикет "".htmlDecode($ticket->subject)."" (ID # $ticket->id) назначен администрацией на $admin->name [$admin->login].nnПерейти к тикету можно по ссылке: ".$full_www_path.$admin_script."?do=tickets&sub=view&id=$ticket->idnnСообщение:nn".htmlDecode($ticket->message);
WriteMailLog($subject_msg,$message);
sendmail($admin->email,'',$support_email,$subject_msg,$message);
if (GetSetting("smsGateway")) {
$smsmsg = "[".$_prioritysms[$priority]."] Ticket assign #$ticketid: $subject";
$admIds=GetAdminIdsWhereTrueParam("sms_sendticketnew");
while (list($i,$aid) = @each($admIds)) {
$smsAdmin=GetAdminById($aid);
if ($smsAdmin->id == $admin->id and $smsAdmin->mobile) {
sendSMS('',$aid,$smsmsg);
}
}
}
writeAdminLog("Тикет ID # $id назначен на $admin->name [$admin->login]");
print "Тикет успешно назначен на $admin->name [$admin->login].<br><br>";
print "[ <a href=?do=tickets&sub=view&id=$id>вернуться в тикет</a> ] [ <a href=?do=tickets>перейти к списку тикетов</a> ]<BR><BR>";
}
if ($sub == "unattach" and $id) {
checkAdminAccess('ticketsEdit',1);
@mysql_query("update tickets set attached='0' where id='$id'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
writeAdminLog("Откреплен тикет ID # $id");
print "Тикет успешно откреплен.<br><br>";
print "[ <a href=?do=tickets&sub=view&id=$id>вернуться в тикет</a> ] [ <a href=?do=tickets>перейти к списку тикетов</a> ]<BR><BR>";
}
if ($sub == "view" and $id) {
checkAdminAccess('ticketsRead',1);
if ($sub2 == "delfile" and $id and $file) {
if ($msgid) {$idd = $msgid; } else { $idd = $id; }
$r=@mysql_query("select attachedFiles from tickets where id='$idd'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
$rr=@mysql_fetch_object($r);
$ok = 0;
$attachedRes=array();
$atatchedFiles = mb_split(":x:",$rr->attachedFiles);
while (list($mm,$oneFile) = @each($atatchedFiles)) {
$one = @mb_split("::",$oneFile);
if ($one[0] == $file) {
$ok=1;
@unlink($full_home_path."/_rootfiles/".$file);
} else {
$attachedRes[] = $oneFile;
}
}
if (@count($attachedRes) > 0) {
$attachedRes = @join(":x:",$attachedRes);
} else {
$attachedRes = "";
}
if ($ok) {
@mysql_query("update tickets set attachedFiles='$attachedRes' where id='$idd'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
}
}
$tckt = GetTicketById($id);
$r=@mysql_query("select * from tickets where id='$id' or parentid='$id' order by id") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
if (mysql_num_rows($r) == 0) {print "<font color=red>Тикет не найден. Возможно он был удален.</font><br><br>";}
else if ($tckt->assignedto and $tckt->assignedto != $_SESSION["adminId"] and !$_SESSION["adminFullAccess"]) { print "<font color=red>Доступ запрещен. Тикет назначен на другого пользователя.</font><br><br>"; }
else {
$totalMsgs = mysql_num_rows($r);
$admUser = GetAdminById($_SESSION["adminId"]);
@mysql_query("update tickets set newforadmin='0' where id=$id") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
print "<table cellpadding=3 width=99%>";
$sendadminsms = 0;
while ($rr = mysql_fetch_object($r)) {
$cnt++;
if ($cnt == 1 and ($rr->adminname or $rr->adminId)) { $firstMsgByAdmin = true; }
if ($rr->userid and !$rr->adminId and !$rr->adminname) {
$isAdminMsg = false;
if (!$firstMsgByAdmin) { $type="Сообщение"; } else { $type="Ответ"; }
$img="<img src="./_rootimages/ticket_user.gif" width=42>";
$rating = "";
} else {
$isAdminMsg = true;
if ($rr->adminId) {
$admin = GetAdminById($rr->adminId);
if ($admin->name) {
$adminNameT=" ($admin->name)";
} else if ($rr->adminname) {
$adminNameT=" ($rr->adminname)";
} else {
$adminNameT="";
}
} else if ($rr->adminname) {
$adminNameT=" ($rr->adminname)";
} else {
$adminNameT="";
}
if ($firstMsgByAdmin) { $type="Сообщение"; } else { $type="Ответ"; }
$type=$type."$adminNameT";
if ($admin->avatar and file_exists($full_home_path."/_rootimages/avatars/".$admin->avatar)) {
$img = "<img src="./_rootimages/avatars/".$admin->avatar."">";
} else {
$img = "<img src="./_rootimages/ticket_admin.gif">";
}
if ($cnt > 1) {
if ($rr->rating) {
$rating = " | Оценка: <span id='$rr->id'></span><script type='text/javascript'> SmartStars.init('$rr->id', null, -$rr->rating, 5, './_rootimages/offstar.gif', './_rootimages/onstar.gif'); </script>";
} else {
$rating = " | Оценка: <span id='$rr->id'></span><script type='text/javascript'> SmartStars.init('$rr->id', null, -$rr->rating, 5, './_rootimages/offstar.gif', './_rootimages/offstar.gif'); </script>";
}
} else {
$rating = "";
}
}
if (!$isAdminMsg) {
$user = GetUserById($rr->userid);
$profile = GetUserProfileByUserId($rr->userid);
if ($profile->org == "3") {
if ($profile->firma) {
$namePrint = " ($profile->firma)";
} else {
$namePrint = "";
}
} else if ($profile->org == "2" or $profile->org == "1") {
if ($profile->surname or $profile->name or $profile->otchestvo) {
$namePrint = " ($profile->surname $profile->name $profile->otchestvo)";
} else {
$namePrint = "";
}
} else {
$namePrint = "";
}
if ($user->id) {
$user = " | Клиент: <A href=?do=fullinfo&id=$rr->userid target=_blank>$user->login</a>$namePrint";
}
} else {
$user = "";
}
if ($cnt == 1) {
$sendadminsms = $rr->sendadminsms;
$priority="| Важность: <img src="./_rootimages/priority_".$rr->priority.".gif" alt="Важность ".$_priority[$rr->priority]."">";
$status="| Статус: <img src="./_rootimages/ticket_".$rr->status.".gif" alt="Тикет ".$_statusTicket[$rr->status]."">";
if ($rr->status == "open" or $rr->status == "wait") {$close="<A href=?do=$do&sub=close&id=$id&uid=$rr->userid onclick="javascript: return confirm('Вы уверены, что хотите закрыть тикет?');"><img src=./_rootimages/close.gif border=0 alt='Закрыть тикет'> закрыть тикет</a> | ";}
if ($rr->status == "closed" or $rr->status == "open") {$wait="<A href=?do=$do&sub=wait&id=$id&uid=$rr->userid onclick="javascript: return confirm('Вы уверены, что хотите перевести тикет в ожидание?');"><img src=./_rootimages/ticket_wait.gif border=0 alt='Перевести тикет в ожидание'> перевести в ожидание</a> | ";}
if (!$rr->attached) {$attach="<A href=?do=$do&sub=attach&id=$id onclick="javascript: return confirm('Вы уверены, что хотите прикрепить тикет?');"><img src=./_rootimages/attach.gif border=0 alt='Прикрепить тикет'> прикрепить тикет</a> | ";}
else {$attach="<A href=?do=$do&sub=unattach&id=$id onclick="javascript: return confirm('Вы уверены, что хотите открепить тикет?');"><img src=./_rootimages/attach.gif border=0 alt='Открепить тикет'> открепить тикет</a> | ";}
print "<tr><td colspan=2 align=center bgcolor=$font_head>Просмотр тикета: <B>".$rr->subject."</b></td></tr>";
if ($rr->assignedto) { $assignedto = GetAdminById($rr->assignedto); print "<tr><td colspan=2 align=center bgcolor=$font_head><font color=red>Тикет назначен на <B>$assignedto->name [$assignedto->login]</b></font></td></tr>"; }
$delmsg="";
$department = $rr->department;
} else {
$priority="";$status="";
$delmsg = "<A href=?do=$do&sub=delmsg&id=$id&msgid=$rr->id onclick="javascript: return confirm('Вы уверены, что хотите удалить сообщение?');"><img src=./_rootimages/del.gif border=0 alt='Удалить сообщение'></a>";
}
if (preg_match("/rn/u", $rr->message)) { $rr->message = preg_replace("/rn/u", "<BR>", $rr->message); } else if (preg_match("/r/u", $rr->message)) { $rr->message = preg_replace("/r/u", "<BR>", $rr->message); }
$rr->message = convertToLinks($rr->message);
if ($rr->attachedFiles) {
$attachedPrint=array();
$atatchedFiles = mb_split(":x:",$rr->attachedFiles);
while (list($mm,$oneFile) = @each($atatchedFiles)) {
$oneFile = @mb_split("::",$oneFile);
$attachedPrint[] = "<a href='?do=getfile&file=$oneFile[0]&realname=$oneFile[1]'>$oneFile[1]</a> <A href='?do=$do&sub=view&sub2=delfile&id=$id&file=$oneFile[0]&msgid=$rr->id' onclick="javascript: return confirm('Вы уверены, что хотите удалить файл?');"><img src="./_rootimages/del.gif" alt="Удалить файл $oneFile[1]"></a>";
}
$attachedPrint = "<B>Прикрепленные файлы:</B> ".@join(", ",$attachedPrint);
} else {
$attachedPrint = "";
}
if ($cnt == $totalMsgs and $admin->id == $admUser->id) { $editMsg = "<A href=?do=$do&sub=view&sub2=editreply&id=$id&msgid=$rr->id><img src='./_rootimages/edit.gif' alt='Изменить сообщение'></a>"; } else { $editMsg = ""; }
print "<tr><td bgcolor=$font_row2 colspan=2><b>#$cnt $type</b> | Дата: $rr->dt $priority $status $user $rating $editMsg $delmsg</td></tr>";
print "<tr bgcolor=$font_row1><td width=60 valign=top>$img</td><td valign=top>$rr->message<br><br>$attachedPrint</td></tr>";
}
print "<table>";
print "$attach $wait $close <A href=?do=$do&sub=delete&id=$id onclick="javascript: return confirm('Вы уверены, что хотите удалить тикет?');"><img src=./_rootimages/del.gif border=0 alt='Удалить тикет'> удалить тикет</a><br><br>";
$admGroups = GetAdminGroups();
if (@mysql_num_rows($admGroups) > 0) {
print "<form action=$admin_script method=POST>";
print "<input type=hidden name=do value=$do>";
print "<input type=hidden name=sub value=movedepartment>";
print "<input type=hidden name=id value=$id>";
print "<B>Перенести тикет в отдел:</b> <select name=department><option></option>";
while ($admGroup = @mysql_fetch_object($admGroups)) {
if ($department != $admGroup->id) {
print "<option value=$admGroup->id>$admGroup->name</option>";
}
}
print "</select> <input type=submit value=Перенести></form><BR><BR>";
}
if ($_SESSION["adminFullAccess"]) {
$q=@mysql_query("select * from admin_users where id<>'".$_SESSION["adminId"]."' order by name") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
if (mysql_num_rows($q) > 0) {
print "<form action=$admin_script method=POST>";
print "<input type=hidden name=do value=$do>";
print "<input type=hidden name=sub value=assignto>";
print "<input type=hidden name=id value=$id>";
print "<B>Назначить тикет на:</b> <select name=adminid><option></option>";
while ($qq = @mysql_fetch_object($q)) {
print "<option value=$qq->id>$qq->name [$qq->login]</option>";
}
print "</select> <input type=submit value=Назначить></form><BR><BR>";
}
}
if ($sub2 == "editreply") {
$q=@mysql_query("select * from tickets where id='$msgid'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
$q=@mysql_fetch_object($q);
$message = $q->message;
$title = "Изменить ответ";
$titleButton = "Изменить";
} else {
$title = "Добавить сообщение";
$titleButton = "Добавить";
}
?>
<table border=0><form method=post enctype="multipart/form-data">
<tr><td colspan=2 align=center bgcolor=<? print $font_head?>><B><? print $title?></b></td></tr>
<input type=hidden name=do value=<? print $do?>>
<? if ($sub2 == "editreply") { ?>
<input type=hidden name=sub value=editreply>
<input type=hidden name=msgid value=<? print $msgid?>>
<? } else { ?>
<input type=hidden name=sub value=reply>
<? } ?>
<input type=hidden name=id value=<? print $id?>>
<tr><td valign=top>Сообщение:</td><td><textarea name=message cols=70 rows=10><? print $message?></textarea></td></tr>
<? if ($admUser->sms_sendticketreply) {?><tr><td></td><td><input type=checkbox name=sendadminsms value="1" <? if ($sendadminsms) {print "checked";} ?>> уведомлять об ответах с помощью SMS <img src="./_rootimages/question.gif" alt="Уведомление получит админ, который последним ответил в данном тикете."></td></tr><? } ?>
<? if ($sub2 != "editreply") { ?>
<tr><td colspan=2 align=center onclick="myShow('s1');" onmouseover="this.bgColor='<? print $font_headm?>'; this.style.cursor='pointer'" onmouseout="this.bgColor='<? print $font_head?>'" bgcolor=<? print $font_head?>><B>Прикрепить файлы</b></td></tr>
<tr><td colspan=2>
<div id="s1" style="display: none;">
<table width=100%>
<tr><td>Файл №1:</td><td><input type=file name=userfile[0]></td><td>Файл №5:</td><td><input type=file name=userfile[4]></td></tr>
<tr><td>Файл №2:</td><td><input type=file name=userfile[1]></td><td>Файл №6:</td><td><input type=file name=userfile[5]></td></tr>
<tr><td>Файл №3:</td><td><input type=file name=userfile[2]></td><td>Файл №7:</td><td><input type=file name=userfile[6]></td></tr>
<tr><td>Файл №4:</td><td><input type=file name=userfile[3]></td><td>Файл №8:</td><td><input type=file name=userfile[7]></td></tr>
</table>
</div>
</td></tr>
<? } ?>
<tr><td colspan=2 align=center bgcolor=<? print $font_head?>><input type=Submit value="<? print $titleButton?>"></td></tr></table><BR></form>
<?
}
}
}
}
if (!$sub) {
checkAdminAccess('ticketsRead',1);
if ($autorefresh and IsNewTicketsForAdmin()) {
?>
<script language="JavaScript">
function settitle(current) {
var a = "Внимание!";
var b = "Новый тикет/ответ!";
if (current == a) {
document.title = b;
} else {
document.title = a;
}
setTimeout("settitle(document.title)", 1000);
}
settitle(document.title);
</script>
<?
}
getfont();
?>
<table width=99%>
<tr>
<Td valign=top>
<table width=370>
<tr><td align=center bgcolor=<? print $font_head?>><B>Поиск</b></td></tr>
<tr><td bgcolor=<? print $font_row?>><form method=post><input type=hidden name=status value=all><input type=hidden name=department value=0><input type=hidden name=uid value=<? print $uid?>><select name=param><option value=subjectmessages>Тема и сообщения:</option><option value=subject>Тема:</option><option value=messages>Сообщения:</option></select> <input type=text name=search size=20> <input type=submit value=Найти></form></td></tr>
</table>
</td>
<td width=100%></td>
</tr>
</table><BR>
<?
$r = @mysql_query("select * from tickets where parentid=0 and attached='1' order by newforadmin, id desc") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
if (mysql_num_rows($r) > 0 and !$param) {
?>
<table cellpadding=3 width=99%>
<tr><td colspan=9 align=right><? print $txt?></td></tr>
<tr><td colspan=9 align=center bgcolor=<? print $font_head?>><B>Прикрепленные тикеты</b></td></tr>
<tr bgcolor=<? print $font_head?> align=center><td>ID#</td><td></td><td>Отдел</td><td>Тема</td><td>Клиент</td><td>Создан</td><td>Последний ответ</td><td>Ответов</td><td></td></tr>
<?
$cnt=0;
while ($rr = @mysql_fetch_object($r)) {
getfont();
$cnt++;
$subj=$rr->subject; if ($rr->newforadmin) {$subj="<b>$subj</b>";}
$dt = mb_split(' ', $rr->dt); $dt=mydate($dt[0])."<BR><font color=#AEAEAE>".$dt[1]."</font>";
$replys=@mysql_query("select COUNT(*) as cnt from tickets where parentid='$rr->id'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
$replys=mysql_fetch_object($replys);
$link="?do=$do&sub=view&id=$rr->id";
$delete="<A href=?do=$do&sub=delete&id=$rr->id onclick="javascript: return confirm('Вы уверены, что хотите удалить тикет?');"><img src=./_rootimages/del.gif border=0 alt='Удалить тикет'></a>";
$close=" <A href=?do=$do&sub=close&id=$rr->id&uid=$rr->userid onclick="javascript: return confirm('Вы уверены, что хотите закрыть тикет?');"><img src=./_rootimages/close.gif border=0 alt='Закрыть тикет'></a>";
$user = GetUserById($rr->userid);
$user = "<A target=_blank href=?do=fullinfo&id=$rr->userid>$user->login</a>";
if ($rr->department) {
$departmentTxt = GetAdminGroupById($rr->department);
$departmentTxt = $departmentTxt->name;
} else {
$departmentTxt = "";
}
$lastreply=@mysql_query("select id,dt from tickets where parentid='$rr->id' order by id desc") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
$lastreply=mysql_fetch_object($lastreply);
if ($lastreply->id) {
$rdt = mb_split(' ', $lastreply->dt); $rdttime=$rdt[1]; $rdt=mydate($rdt[0]);
$lastreply = $rdt."<BR><font color=#AEAEAE>".$rdttime."</font>";
} else {
$lastreply = "-";
}
if ($rr->attachedFiles) { $attachedFiles = " <img src='./_rootimages/attach.gif' alt='Есть прикрепленные файлы'"; } else {$attachedFiles = "";}
?>
<tr bgcolor="<? print $font_row?>" height=30>
<td valign=middle align=center> <? print $rr->id?> </td>
<td valign=middle width=50 align=center> <img src="./_rootimages/priority_<? print $rr->priority?>.gif" alt="Важность <? print $_priority[$rr->priority]?>"> <img src="./_rootimages/ticket_<? print $rr->status?>.gif" alt="Тикет <? print $_statusTicket[$rr->status]?>"><? print $attachedFiles?> </td>
<td valign=middle align=center> <? print $departmentTxt?> </td>
<td> <a href=<? print $link?>><? print $subj?></a> </td>
<td align=center> <? print $user?> </td>
<td align=center> <? print $dt?> </td>
<td align=center> <? print $lastreply?> </td>
<td align=center><? print $replys->cnt?></td>
<td align=center><? print $delete?> <?if ($rr->status == "open") {print $close;}?></td>
</tr>
<?
}
?>
<tr bgcolor=<? print $font_head?>><Td colspan=9>Прикрепленных тикетов: <? print $cnt?></td></td></tr>
<tr><td colspan=9 align=right><? print $txt?></td></tr>
</table><br>
<?
}
$myStatus = $_SESSION["ticketsStatus"]; if (!$myStatus) { $myStatus="open"; }
if ($status and $status != $myStatus) { $myStatus = $status; $_SESSION["ticketsStatus"] = $myStatus; }
if (!$myStatus or $myStatus == "open") {$status="and (status='open' or status='wait')"; $statustxt=$_lang[TicketsStatusOpen];}
else if ($myStatus == "wait") {$status="and status='wait'"; $statustxt=$_lang[TicketsStatusWait];}
else if ($myStatus == "all") {$status=""; $statustxt=$_lang[TicketsStatusAll];}
else {$status="and status='closed'"; $statustxt=$_lang[TicketsStatusClosed];}
$myDepartment = $_SESSION["ticketsDepartment"]; if (!$myDepartment) { $myDepartment="0"; }
if ($department != "" and $department != $myDepartment) { $myDepartment = $department; $_SESSION["ticketsDepartment"] = $myDepartment; }
if (!$myDepartment) {$department=""; $departmenttxt=$_lang[TicketsStatusAll];}
else {$department="and department='$myDepartment'"; $departmenttxt=GetAdminGroupById($myDepartment); $departmenttxt=$departmenttxt->name;}
if ($uid) {$mysqlUserAddon = "and userid='$uid'";}
if ($search) {
if ($param == 'subject') { $operat = "$param LIKE '%$search%'"; }
else if ($param == "messages" or $param == "subjectmessages") {
$resSearchArray = array();
if ($param == "subjectmessages") {
$searchAddon = "OR subject LIKE '%$search%'";
}
$c = @mysql_query("select id,parentid from tickets where message LIKE '%$search%' $searchAddon") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
while ($cc = @mysql_fetch_object($c)) {
if ($cc->parentid) { $iddd = $cc->parentid; }
else { $iddd = $cc->id; }
$resSearchArray[$iddd] = "1";
}
if (count($resSearchArray) > 0) {
reset($resSearchArray);
while (list($k,$v) = @each($resSearchArray)) {
$operat[] = "id=$k";
}
$operat = @join(" OR ",$operat);
$operat = "(".$operat.")";
}
}
if ($operat) {
$mysqlUserAddon .= " and $operat";
} else {
$mysqlUserAddon .= " and NOT(id)";
}
}
if ($search) {
$titleTxt = "результат поиска";
} else {
$titleTxt = "$statustxt, $departmenttxt";
}
$r = @mysql_query("select * from tickets where parentid=0 $status $department $mysqlUserAddon order by newforadmin, id desc") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
$rows = mysql_num_rows($r);
list($start, $perPage, $txt) = MakePages($page, $rows, "status=$myStatus&uid=$uid&department=$myDepartment¶m=$param&search=$search");
?>
<table cellpadding=3 width=99%>
<tr><td colspan=9 align=right><? print $txt?></td></tr>
<tr><td colspan=9 align=center bgcolor=<? print $font_head?>><B>Тикеты [ <? print $titleTxt?> ]</b></td></tr>
<tr><td colspan=9 align=center bgcolor=<? print $font_head?>><? print $_lang[TicketsShow]?>: [ <a href=?do=tickets&department=<? print $myDepartment?>&status=all&uid=<? print $uid?>><? print $_lang[TicketsStatusAll]?></a> ] [ <a href=?do=tickets&department=<? print $myDepartment?>&status=open&uid=<? print $uid?>><? print $_lang[TicketsStatusOpen]?></a> ] [ <a href=?do=tickets&department=<? print $myDepartment?>&status=closed&uid=<? print $uid?>><? print $_lang[TicketsStatusClosed]?></a> ] [ <a href=?do=tickets&department=<? print $myDepartment?>&status=wait&uid=<? print $uid?>><? print $_lang[TicketsStatusWait]?></a> ]</td></tr>
<tr><td colspan=9 align=center bgcolor=<? print $font_head?>><? print $_lang[TicketsDepartment]?>: [ <a href=?do=tickets&department=0&status=<? print $myStatus?>&uid=<? print $uid?>><? print $_lang[TicketsStatusAll]?></a> ]
<?
$admGroups = GetAdminGroups();
if (@mysql_num_rows($admGroups) > 0) {
while ($admGroup = @mysql_fetch_object($admGroups)) {
print "[ <a href=?do=tickets&department=$admGroup->id&status=$myStatus&uid=$uid>$admGroup->name</a> ] ";
}
}
?>
</td></tr>
<tr bgcolor=<? print $font_head?> align=center><td>ID#</td><td></td><td>Отдел</td><td>Тема</td><td>Клиент</td><td>Создан</td><td>Последний ответ</td><td>Ответов</td><td></td></tr>
<?
$r = @mysql_query("select * from tickets where parentid=0 $status $department $mysqlUserAddon order by newforadmin, id desc LIMIT $start,$perPage") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
$cnt=0;
while ($rr = @mysql_fetch_object($r)) {
getfont();
$cnt++;
$subj=$rr->subject; if ($rr->newforadmin) {$subj="<b>$subj</b>";}
$dt = mb_split(' ', $rr->dt); $dt=mydate($dt[0])."<BR><font color=#AEAEAE>".$dt[1]."</font>";
$replys=@mysql_query("select COUNT(*) as cnt from tickets where parentid='$rr->id'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
$replys=mysql_fetch_object($replys);
$link="?do=$do&sub=view&id=$rr->id";
$delete="<A href=?do=$do&sub=delete&id=$rr->id onclick="javascript: return confirm('Вы уверены, что хотите удалить тикет?');"><img src=./_rootimages/del.gif border=0 alt='Удалить тикет'></a>";
$close=" <A href=?do=$do&sub=close&id=$rr->id&uid=$rr->userid onclick="javascript: return confirm('Вы уверены, что хотите закрыть тикет?');"><img src=./_rootimages/close.gif border=0 alt='Закрыть тикет'></a>";
$user = GetUserById($rr->userid);
$user = "<A target=_blank href=?do=fullinfo&id=$rr->userid>$user->login</a>";
if ($rr->department) {
$departmentTxt = GetAdminGroupById($rr->department);
$departmentTxt = $departmentTxt->name;
} else {
$departmentTxt = "";
}
$lastreply=@mysql_query("select id,dt from tickets where parentid='$rr->id' order by id desc") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
$lastreply=mysql_fetch_object($lastreply);
if ($lastreply->id) {
$rdt = mb_split(' ', $lastreply->dt); $rdttime=$rdt[1]; $rdt=mydate($rdt[0]);
$lastreply = $rdt."<BR><font color=#AEAEAE>".$rdttime."</font>";
} else {
$lastreply = "-";
}
if ($rr->attachedFiles) { $attachedFiles = " <img src='./_rootimages/attach.gif' alt='Есть прикрепленные файлы'"; } else {$attachedFiles = "";}
?>
<tr bgcolor="<? print $font_row?>" height=30>
<td valign=middle align=center> <? print $rr->id?> </td>
<td valign=middle width=60 align=center> <img src="./_rootimages/priority_<? print $rr->priority?>.gif" alt="Важность <? print $_priority[$rr->priority]?>"> <img src="./_rootimages/ticket_<? print $rr->status?>.gif" alt="Тикет <? print $_statusTicket[$rr->status]?>"><? print $attachedFiles?> </td>
<td valign=middle align=center> <? print $departmentTxt?> </td>
<td> <a href=<? print $link?>><? print $subj?></a> </td>
<td align=center> <? print $user?> </td>
<td align=center> <? print $dt?> </td>
<td align=center> <? print $lastreply?> </td>
<td align=center><? print $replys->cnt?></td>
<td align=center><? print $delete?> <?if ($rr->status == "open") {print $close;}?></td>
</tr>
<?
}
?>
<tr bgcolor=<? print $font_head?>><Td colspan=9>Всего тикетов: <? print $rows?>, тикетов на странице: <? print $cnt?></td></td></tr>
<tr><td colspan=9 align=right><? print $txt?></td></tr>
</table>
<? if (!$uid) { ?>
<form method=post>
<input type=hidden name=do value=tickets>
<input type=hidden name=sub value=setrefresh>
Обновлять страницу с тикетами каждые <input type=text size=3 name=refreshtime value=<? print intval(GetSetting("tickets_refresh"))?>> секунд <input type=submit value=OK>
</form>
<? } ?>
<?
}
?>