Exemplo n.º 1
0
 function Set($arFields, $arFieldsSLA)
 {
     global $DB, $APPLICATION;
     $err_mess = self::err_mess() . "<br>Function: Set<br>Line: ";
     $isDemo = null;
     $isSupportClient = null;
     $isSupportTeam = null;
     $isAdmin = null;
     $isAccess = null;
     $userID = null;
     CTicket::GetRoles($isDemo, $isSupportClient, $isSupportTeam, $isAdmin, $isAccess, $userID);
     if (!$isAdmin) {
         $arMsg = array();
         $arMsg[] = array("id" => "PERMISSION", "text" => GetMessage("SUP_ERROR_ACCESS_DENIED"));
         $e = new CAdminException($arMsg);
         $APPLICATION->ThrowException($e);
         return false;
     }
     if (is_array($arFields)) {
         $f = new CSupportTableFields(self::$holidays);
         $f->FromArray($arFields);
     } else {
         $f = $arFields;
     }
     if (is_array($arFieldsSLA)) {
         $f_s = new CSupportTableFields(self::$sla2holidays, CSupportTableFields::C_Table);
         $f_s->FromTable($arFieldsSLA);
     } else {
         $f_s = $arFieldsSLA;
     }
     $table = self::table;
     $table_s2h = self::table_s2h;
     $isNew = $f->ID <= 0;
     $objError = new CAdminException(array());
     if (strlen($f->NAME) <= 0) {
         $objError->AddMessage(array("text" => GetMessage('SUP_ERROR_EMPTY_NAME')));
     }
     if (strlen($f->OPEN_TIME) <= 0) {
         $objError->AddMessage(array("text" => GetMessage('SUP_ERROR_EMPTY_OPEN_TIME')));
     }
     $zd = mktime(0, 0, 0, 1, 1, 2010);
     if ($f->DATE_FROM < $zd || $f->DATE_FROM === null || $f->DATE_TILL < $zd || $f->DATE_TILL === null || $f->DATE_FROM > $f->DATE_TILL) {
         if ($f->DATE_FROM < $zd || $f->DATE_FROM === null) {
             $f->DATE_FROM = time() + CTimeZone::GetOffset();
         }
         if ($f->DATE_TILL < $zd || $f->DATE_TILL === null) {
             $f->DATE_TILL = time() + CTimeZone::GetOffset();
         }
         $objError->AddMessage(array("text" => GetMessage('SUP_ERROR_EMPTY_DATE')));
     }
     if (count($objError->GetMessages()) > 0) {
         $APPLICATION->ThrowException($objError);
         return false;
     }
     $arFields_i = $f->ToArray(CSupportTableFields::ALL, array(CSupportTableFields::NOT_NULL), true);
     $res = 0;
     if (count($arFields_i) > 0) {
         if ($isNew) {
             $res = $DB->Insert($table, $arFields_i, $err_mess . __LINE__);
             $f->ID = $res;
         } else {
             $res = $DB->Update($table, $arFields_i, "WHERE ID=" . $f->ID . "", $err_mess . __LINE__);
         }
     }
     if (intval($res) <= 0) {
         $APPLICATION->ThrowException(GetMessage('SUP_ERROR_DB_ERROR'));
         return false;
     }
     $DB->Query("DELETE FROM {$table_s2h} WHERE HOLIDAYS_ID = " . $f->ID, false, $err_mess . __LINE__);
     $f_s->ResetNext();
     while ($f_s->Next()) {
         $f_s->HOLIDAYS_ID = $f->ID;
         if ($f_s->SLA_ID > 0) {
             $strSql = "INSERT INTO " . $table_s2h . "(SLA_ID, HOLIDAYS_ID) VALUES (" . $f_s->SLA_ID . ", " . $f_s->HOLIDAYS_ID . ")";
             $res = $DB->Query($strSql, false, $err_mess . __LINE__);
         }
     }
     CSupportTimetableCache::toCache(array("SLA_ID" => $f_s->getColumn("SLA_ID")));
     return $f->ID;
 }
Exemplo n.º 2
0
	function checkGPErrors($arFields) {
		$filename = $_SERVER['DOCUMENT_ROOT'] . '/templogbeforeadd.log';
		$data = array("before_add", date('d.m.Y h:i:s'), $_POST, $arResult, $arFields);
		file_put_contents($filename, var_export($data, true), FILE_APPEND | LOCK_EX);
		
		global $APPLICATION;
		$e = new CAdminException();
		$errors = json_decode($_POST['gp_errors']);
		$errors_count = 0;
		if ($arFields['DELIVERY_ID'] == self::$DELIVERY_ID && is_array($errors) && count($errors) > 0) {
			if (CModule::IncludeModule(self::$MODULE_ID)) {
				$e->AddMessage(array("text" => GetMessage("GP_ERRORS_LIST")));
				foreach ($errors as $error_code) {
					if (strlen($error_code) > 0) {
						// $error_message = CGPWidget::Translate($error_code);
						$error_message = $error_code;
						$errors_count++;
						$e->AddMessage(array("text" => trim(htmlspecialchars($error_message))));
					}
				}
				if ($errors_count > 0) {
					$APPLICATION->ThrowException($e);
					return false;
				}
			}
		}
	}