/** * @return mixed */ public function execute() { $data = $this->loginForm->getRawData(['email', 'password']); foreach (config('pckg.auth.providers') as $providerKey => $providerConfig) { /** * Create and set new provider. */ $provider = Reflect::create($providerConfig['type'], [$this->auth]); $provider->setEntity($providerConfig['entity']); /** * If user doesnt exists, don't proceed with execution. */ if (!($user = $provider->getUserByEmailAndPassword($data['email'], sha1($data['password'] . $providerConfig['hash'])))) { continue; } /** * Try to login. */ $this->auth->useProvider($provider, $providerKey); if ($this->auth->performLogin($user)) { /** * @T00D00 - login user on all providers! */ $this->auth->useProvider($provider); trigger('user.loggedIn', [$this->auth->getUser()]); if (isset($data['autologin'])) { $this->auth->setAutologin(); } return $this->successful(); } } return $this->error(); }
public function run($params) { // $oldRevision = 117093; $oldRevision = self::getPrevRevision(); // $oldRevision = null; // 检查m3d配置文件是否已改变 $path = defined('M3D_FILE') ? M3D_FILE : (defined('SRC_ROOT') ? SRC_ROOT . '/m3d.php' : null); if ($path && self::checkFileChange($path, $oldRevision)) { mark('m3d配置文件已改变,重新加载配置,并且进行全量编译', 'especial'); $params[1]->reload(PROJECT_SITE_PATH . '/' . C('PROJECT.SRC_DIR') . '/' . PROJECT_MODULE_NAME . '/' . C('M3D_FILENAME')); C('INCRE.IS_INCRE', false); trigger('m3d_config_change'); } if (isset($_GET['isIncre']) && $_GET['isIncre'] === 'false' || !C('INCRE.IS_INCRE') || is_null($oldRevision)) { // 事件解绑 self::off(); } else { mark('增量编译准备中...', 'emphasize'); $newRevision = IncreMap::getRevision(); self::$files = self::getChangeList($newRevision, $oldRevision); IncreMap::loadBelongMap(); if (!empty(self::$files[self::DELETE])) { IncreMap::rebuildBelongMap(self::$files[self::DELETE]); } // 更新modify列表 self::$files[self::MODIFY] = array_unique(array_merge(self::$files[self::MODIFY], IncreMap::getAffectList(self::$files[self::MODIFY]))); } }
function __invoke($error, $method, $path, \cms\Sphido $cms) { trigger(MissingPage::class . '_before', $error, $method, $path, $cms); if ($cms->page = Page::fromPath(\dir\content() . '/404', (array) \app\config()->meta)) { return $cms->render(); } trigger(MissingPage::class . '_default', $error, $method, $path, $cms); }
/** * @return Engine */ function latte() { $latte = new Engine(); $latte->setLoader(filter('latte.loader', new FileLoader())); $latte->setTempDirectory(\dir\cache()); $latte->addFilter('md', '\\cms\\md'); trigger('latte.macroset', new MacroSet($latte->getCompiler())); return filter('latte', $latte); }
private function handle($matches) { $path = Tool::getActualPath($matches[1]); $processor = new JsPreprocess($this->processor->getMap()); $processor->setFile(C('SRC.SRC_PATH') . $path); $processor->process(); trigger('js_import', $this->processor, $processor); return $processor->getContents(); }
/** * @return Engine */ function latte() { $latte = new Engine(); $latte->setLoader(filter(FileLoader::class, new FileLoader())); $latte->setTempDirectory(\dir\cache()); $latte->addFilter('md', '\\cms\\md'); trigger(MacroSet::class, new MacroSet($latte->getCompiler())); return filter(Engine::class, $latte); }
/** * @return mixed */ public function execute() { $rUser->setArray($this->request->post()); $rUser->hashPassword(); if ($rUser->save()) { trigger('user.registered', [$rUser]); return $this->successful(); } return $this->error(); }
private function replaceMediaPath($matches) { $path = $matches[0]; $aPath = Tool::getActualPath($path); if (isset($this->map['media'][$aPath])) { trigger('js_replace', $this, $aPath); return Tool::addCdn($this->map['media'][$aPath]); } return $path; }
public function run() { trigger('imerge_start', $this); mark('开始自动合图扫描', 'emphasize'); $files = get_files_by_type(C('SRC.SRC_PATH'), 'css'); $generator = new MergeConfigGenerator($files); $generator->generate(); $writer = new MergeConfigWriter(C('IMERGE_PATH')); $writer->writeImageConfig($generator->getConfig()); // 更新大图 $this->updateSprite(); trigger('imerge_end', $this); }
public static final function getInstance($class, $options = null) { if (empty($class)) { return null; } $class = ucfirst(strtolower($class)) . 'Compressor'; if (!isset(self::$_instance[$class])) { $instance = new stdClass(); $instance->return = null; trigger('get_compressor', $instance, $options); self::$_instance[$class] = is_null($instance->return) ? empty($options) ? new $class() : new $class($options) : $instance->return; } return self::$_instance[$class]; }
public function publishMETA() { $title = trigger('page_title', $this->pageTitle); if (empty($title) || !isset($title)) { publish('<title>' . $this->pageTitle . '</title>'); } else { publish('<title>' . $title . '</title>'); } publish('<meta name="description" content="' . $this->pageDesc . '">'); publish('<meta name="keywords" content="' . $this->pageTags . '">'); if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) { publish('<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>'); } publish('<script>var resourceURL = "/' . currentSite()->relativePath . 'res/' . '";</script>'); }
/** * Page not found error. * * @param $error * @param callable $method * @param string $path * @param Sphido $cms * @return int|null */ public function error($error, $method, $path, $cms) { trigger('render.error', $error, $method, $path, $cms); if ($this->page = Page::fromPath(\dir\content() . '/404', (array) config()->meta)) { return print ensure('render.error', [$this, 'render'], $this); } /** * @param int $error * @param string $method * @param string $path * @param Sphido $cms * @name render .default.error */ ensure('render.default.error', $error, $method, $path, $cms); // default error is on you }
/** * @return mixed|null|string * @throws \Exception */ public function render() { trigger(Sphido::class . '::' . __FUNCTION__, $this->page, $this); // HTTP status code if ($code = isset($this->page->status) ? $this->page->status : null) { http_response_code($code); } // PHTML file execute if ($this->page->is('phtml')) { extract(get_object_vars($this), EXTR_SKIP); ob_start(); require $this->page; return ob_get_clean(); } return latte()->renderToString($this->page, get_object_vars($this)); }
public function run($params) { $item = $params[2]; if ($this->options['requirejs.path'] && $item['processor'] === 'js') { mark('requireJs插件开始处理' . $this->options['requirejs.path'], 'emphasize'); $this->options['requirejs.path'] = C('SRC.SRC_PATH') . $this->options['requirejs.path']; if (!file_exists($this->options['requirejs.path'])) { mark('"' . $this->options['requirejs.path'] . '"不存在,请检查m3d.php中requireJs配置', 'error'); return; } $tool = $params[1]; $map = $this->getMap($tool); $script = $this->genScript($map); $processor = Preprocess::getInstance('js'); $mapFiles = $this->options['requirejs.path']; if (is_string($mapFiles)) { $mapFiles = array($mapFiles); } foreach ($mapFiles as $file) { $processor->setFile($file); $processor->setContents($script); $processor->process(); $processor->compress(); $path = $processor->getRelativePath(); $buildPath = $tool->writeBuildFile($processor, $item, $path); $oldBuildPath = $tool->getMap('js', $path); if ($buildPath !== $oldBuildPath) { $tool->updateMap('js', $path, $buildPath); // 清除文件 $file = C('SRC.BUILD_PATH') . $oldBuildPath; if (file_exists($file)) { unlink($file); } $file = C('SRC.BUILD_CACHE_PATH') . $oldBuildPath; if (file_exists($file)) { unlink($file); } trigger('change_file', $path); } } } }
/** * 绘制图像 * @param $type */ public function draw($type, $config = array()) { if (empty($config)) { $loader = new MergeConfigLoader($this->imergePath); $config = $loader->getImageConfigByType($type); } $imgList = array(); if (!empty($config)) { foreach ($config as $key => $value) { try { $imgList[$key] = new Image($this->staticRelativePath . $key, $value); } catch (ImageException $e) { mark("合图{$type}中,存在小图{$key}的配置文件,但该小图不存在,请到合图配置界面删除该小图", 'warn'); } } } $layout = new Layout($imgList); $spriteConfigs = array(); $spriteConfigs[$type] = array(); if ($layout->reflow($width, $height)) { $this->sprite = imagecreatetruecolor($width, $height); imagealphablending($this->sprite, false); imagesavealpha($this->sprite, true); imagefill($this->sprite, 0, 0, imagecolorallocatealpha($this->sprite, 0, 0, 0, 127)); $spriteConfigs[$type]['config'] = $this->repaint($this->sprite, $imgList, $width, $height); // 记录sprite的属性 $spriteConfigs[$type]['attr'] = array('filename' => $type . C('SPRITE_SUFFIX') . '.png', 'width' => $width, 'height' => $height); // $spriteConfigs[$type]['filename'] = $type.C('SPRITE_SUFFIX').'.png'; // 生成大图到imerge_sprite_dir $path = $this->imergePath . '/' . C('IMERGE_SPRITE_DIR') . '/' . $type . C('SPRITE_SUFFIX') . '.png'; imagepng($this->sprite, $path); // 写入配置 $writer = new MergeConfigWriter($this->imergePath); $writer->writeSpriteConfig($spriteConfigs); // 派发处理完成事件 trigger('DRAW_SPRITE_END', $path); } }
/** * search in the Incidents DB for incident(s) titles that match the subject of this email * @author Nico du toit * @param string $subject. Normally the subject of an email to compare as from the inbound script * @param string $contactid. The contact id to check the incidents against (saves time .. i think) * @return Returns either YES(continue with auto create), NO (don't auto create) or the incidentID * (of an exact match between the title and the email subject) */ function check_for_duplicates($subject, $contactid) { //Revert to second function that does the preg_match $count_dup = find_duplicate_cases($subject, $contactid); //There is one match for the subject in the DB, array is returned if (is_array($count_dup)) { // TODO: **Depreciated - after verification we can remove this //$incidentid = id_of_duplicate($subject, $contactid); $count = $count_dup[0]; $incidentid = $count_dup[1]; debug_log("Duplicate email sent!! - Reverting with incidentid to import into case !!" . $incidentid); //Just in case the search fails and no ID is retrieved we need to exit correctly if (!$incidentid) { debug_log("Incident ID could not be found as intended !!"); $create = "NO"; return $create; } trigger('TRIGGER_EMAIL_DUPLICATE_IMPORTED', array('incidentid' => $incidentid)); $create = $incidentid; return $create; } //There are multiple matches for the subject in the DB if (!is_array($count_dup) && $count_dup > 1) { $id = 0; $uid = 3; //TODO: For now this is my id but i need to change it to system's later debug_log("Possible duplicate email. Number of cases with similar subject: " . $count_dup . " - NOT auto creating!! /n "); trigger('TRIGGER_POSSIBLE_DUPLICATE', array('incidentid' => $id, 'userid' => $uid, 'emailsubject' => $subject)); $create = "NO"; return $create; } //There are no results thus return and auto create the case if possible if (!is_array($count_dup) && $count_dup == 0) { debug_log("No duplicates found continuiing !!" . $count_dup); $create = "YES"; return $create; } }
public function autoparse() { self::addDir(path('root'), Twig::PRIORITY_LAST); $this->initTwig($this->file); if ($this->file) { $this->twig = $this->twig->loadTemplate($this->file . ".twig"); } else { $this->twig = $this->twig->createTemplate($this->template); } try { /** * Trigger rendering event so we can attach some handlers. */ trigger(RenderingView::class, ['view' => $this->file]); /** * Render template. */ $render = measure('Rendering ' . $this->file, function () { return $this->twig->render($this->getFullData()); }); if ($render == $this->file . '.twig') { if (prod()) { return null; } return '<p style="color: black; font-weight: bold; background-color: red;">' . 'Cannot load file ' . $this->file . '</p>'; } return $render; } catch (Twig_Error_Syntax $e) { return "<pre>Twig error:" . exception($e) . "</pre>"; } catch (Throwable $e) { return '<pre>' . exception($e) . '</pre>'; } }
public function redirect($url = null, $httpParams = [], $routerParams = []) { $output = null; if ($url === -1) { $url = $this->getMinusUrl(); $output = '<html><body><script>history.go(-1);</script></body></html>'; } else { if (substr($url, 0, 1) == '@') { $url = (new URL())->setParams($httpParams)->setUrl($this->router->make(substr($url, 1), $routerParams))->relative(); } else { if ($url === null) { $url = $this->router->getUri(); } } } if (!$output) { $output = '<html><head><meta http-equiv="refresh" content="0; url=' . $url . '" /></head><body></body></html>'; } /** * @T00D00 - implement event */ trigger('response.redirect', [$this]); if (context()->exists(Flash::class)) { context()->get(Flash::class)->__destruct(); } // try with php header("Location: " . $url); // fallback with html $this->respond($output); return $this; }
if ($CONFIG['feedback_form'] != '' and $CONFIG['feedback_form'] > 0 and $send_feedback == TRUE) { create_incident_feedback($CONFIG['feedback_form'], $id); } $notifyexternal = $notifycontact = $awaitingclosure = 0; if ($send_engineer_email == 'yes') { $notifyexternal = 1; } if ($send_email == 'yes') { $notifycontact = 1; if ($wait == 'yes') { $awaitingclosure = 1; } else { $awaitingclosure = 0; } } trigger('TRIGGER_INCIDENT_CLOSED', array('incidentid' => $incidentid, 'userid' => $sit[2], 'notifyexternal' => $notifyexternal, 'notifycontact' => $notifycontact, 'awaitingclosure' => $awaitingclosure)); // Tidy up drafts i.e. delete $draft_sql = "DELETE FROM `{$dbDrafts}` WHERE incidentid = {$id}"; mysql_query($draft_sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } // Check for knowledge base stuff, prior to confirming: if ($_REQUEST['kbarticle'] == 'yes') { $sql = "INSERT INTO `{$dbKBArticles}` (doctype, title, distribution, author, published, keywords) VALUES "; $sql .= "('1', "; $sql .= "'{$kbtitle}', "; $sql .= "'{$distribution}', "; $sql .= "'" . mysql_real_escape_string($sit[2]) . "', "; $sql .= "'" . date('Y-m-d H:i:s', mktime(date('H'), date('i'), date('s'), date('m'), date('d'), date('Y'))) . "', "; $sql .= "'[{$id}]') ";
} $owner = incident_owner($id); // visible update if ($cust_vis == "yes") { $sql = "INSERT INTO `{$dbUpdates}` (incidentid, userid, type, bodytext, timestamp, currentowner, currentstatus, customervisibility, nextaction) "; $sql .= "VALUES ('{$id}', '{$sit['2']}', '{$updatetype}', '{$bodytext}', '{$now}', '{$owner}', '{$newstatus}', 'show' , '{$nextaction}')"; } else { $sql = "INSERT INTO `{$dbUpdates}` (incidentid, userid, type, bodytext, timestamp, currentowner, currentstatus, nextaction) "; $sql .= "VALUES ({$id}, {$sit['2']}, '{$updatetype}', '{$bodytext}', '{$now}', '{$owner}', '{$newstatus}', '{$nextaction}')"; } $result = mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } $updateid = mysql_insert_id(); trigger('TRIGGER_INCIDENT_UPDATED_INTERNAL', array('incidentid' => $id, 'userid' => $sit[2])); //upload file, here because we need updateid if ($_FILES['attachment']['name'] != '') { // try to figure out what delimeter is being used (for windows or unix)... //.... // $delim = (strstr($filesarray[$c],"/")) ? "/" : "\\"; $delim = strstr($_FILES['attachment']['tmp_name'], "/") ? "/" : "\\"; // make incident attachment dir if it doesn't exist $umask = umask(00); if (!file_exists("{$CONFIG['attachment_fspath']}{$id}")) { $mk = @mkdir("{$CONFIG['attachment_fspath']}{$id}", 0770, TRUE); if (!$mk) { $sql = "DELETE FROM `{$dbUpdates}` WHERE id='{$updateid}'"; mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); }
/** * Execute raw sql code */ function sql($sql, $params = array()) { try { $db = service('database'); $statement = $db->prepare($sql); return $statement->execute($params); } catch (PDOException $e) { trigger('database.error', $e, $sql, $params); return false; } }
} if ($email == '') { $errors++; $_SESSION['formerrors']['add_site']['email'] = user_alert(sprintf($strFieldMustNotBeBlank, "'{$strEmail}'"), E_USER_ERROR); } // add site if no errors if ($errors == 0) { if ($owner == '') { $owner = 0; } $sql = "INSERT INTO `{$dbSites}` (name, department, address1, address2, city, county, country, postcode, telephone, fax, email, websiteurl, notes, typeid, owner) "; $sql .= "VALUES ('{$name}', '{$department}' ,'{$address1}', '{$address2}', '{$city}', '{$county}', '{$country}', '{$postcode}', "; $sql .= "'{$telephone}', '{$fax}', '{$email}', '{$websiteurl}', '{$notes}', '{$typeid}','{$owner}')"; $result = mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } $id = mysql_insert_id(); // show error message if addition failed if (!$result) { echo "<p class='error'>{$strAddSiteFailed}</p>\n"; } else { clear_form_data('add_site'); clear_form_errors('add_site'); trigger('TRIGGER_NEW_SITE', array('siteid' => $id, 'userid' => $sit[2])); html_redirect("site_details.php?id={$id}"); } } else { html_redirect($_SERVER['PHP_SELF'], FALSE); } }
<?php $TABLE = $_GET["trigger"]; $trigger_options = trigger_options(); $trigger_event = array("INSERT", "UPDATE", "DELETE"); $dropped = false; if ($_POST && !$error && in_array($_POST["Timing"], $trigger_options["Timing"]) && in_array($_POST["Event"], $trigger_event) && in_array($_POST["Type"], $trigger_options["Type"])) { $timing_event = " {$_POST['Timing']} {$_POST['Event']}"; $on = " ON " . table($TABLE); $dropped = drop_create("DROP TRIGGER " . idf_escape($_GET["name"]) . ($jush == "pgsql" ? $on : ""), "CREATE TRIGGER " . idf_escape($_POST["Trigger"]) . ($jush == "mssql" ? $on . $timing_event : $timing_event . $on) . rtrim(" {$_POST['Type']}\n{$_POST['Statement']}", ";") . ";", ME . "table=" . urlencode($TABLE), array(lang('Trigger has been dropped.'), 'success'), array(lang('Trigger has been altered.'), 'success'), array(lang('Trigger has been created.'), 'success'), $_GET["name"]); } page_header($_GET["name"] != "" ? lang('Alter trigger') . ": " . h($_GET["name"]) : lang('Create trigger'), $error, array("table" => $TABLE)); $row = $_POST; if (!$row) { $row = trigger($_GET["name"]) + array("Trigger" => $TABLE . "_bi"); } ?> <form action="" method="post" id="form"> <table cellspacing="0"> <tr><th><?php echo lang('Time'); ?> <td><?php echo html_select("Timing", $trigger_options["Timing"], $row["Timing"], "if (/^" . preg_quote($TABLE, "/") . "_[ba][iud]\$/.test(this.form['Trigger'].value)) this.form['Trigger'].value = '" . js_escape($TABLE) . "_' + selectValue(this).charAt(0).toLowerCase() + selectValue(this.form['Event']).charAt(0).toLowerCase();"); ?> <tr><th><?php echo lang('Event'); ?> <td><?php echo html_select("Event", $trigger_event, $row["Event"], "this.form['Timing'].onchange();");
public function prepareQuery(Query $query, $recordClass = null) { $this->recordClass = $recordClass; $sql = $query->buildSQL(); $prepare = measure('Prepare query: ' . $sql, function () use($query, $sql) { $binds = $query->buildBinds(); $prepare = $this->getConnection()->prepare($sql); if (!$prepare) { throw new Exception('Cannot prepare statement'); } /** * Trigger query.prepared event. */ trigger(Query::class . '.prepared', ['sql' => $sql, 'binds' => $binds]); $i = 1; foreach ($binds as $key => $val) { if (is_array($val)) { foreach ($val as $rVal) { $prepare->bindValue($i, $rVal); $i++; } } else { $prepare->bindValue($i, $val); $i++; } } $prepare->setFetchMode(\PDO::FETCH_ASSOC); return $prepare; }); return $prepare; }
//used to store messsage key values frim the DB. if (trim($tips) == "") { // if only blank message receives } else { $cachekey = apc_fetch($cache_msg_keys); if ($cachekey !== false) { check_tips_content($cachekey); } echo " KEY MATCHED {$key_matched} FIRST CHECK<br>"; if ($cachekey === false || $key_matched == "") { apc_delete($cache_msg_keys); //DELETES THE CACHE IF EXIST //message cache not found... Fetching from the Database echo "<h2>CACHE BUILDING</h2>"; $query = "SELECT * FROM tips_keys"; $result = mysqli_query($conDb2, $query) or trigger("ERROR in query " . mysql_error()); while ($row = mysqli_fetch_array($result)) { $key = strtolower($row['types']); $values = explode(',', $row['keywords']); //echo "TYPE: " . $key . " KEYWORDS: " . print_r($values) . "<br>"; $cachekey[$key] = $values; } apc_store($cache_msg_keys, $cachekey); //$cachekey = apc_fetch($cache_msg_keys); check_tips_content($cachekey); // echo "CACHE $cachekey KEY MATCHED $key_matched SECOND CHECK<br>"; } } $key_matched = strtolower($key_matched); echo "<h3>MATCHED KEY: {$key_matched} LANGUAGE: {$lang_used}</h3>"; //REPEATING THE SAME CODE ****** MADE OR COPY CODE AS ABOVE CODE CHANGES
$addition_errors_string .= user_alert($strAdditionFail, E_USER_WARNING); } // Add service $sql = "INSERT INTO `{$dbService}` (contractid, startdate, enddate, creditamount, unitrate, incidentrate, foc) "; $sql .= "VALUES ('{$maintid}', '{$startdate}', '{$enddate}', '{$amount}', '{$unitrate}', '{$incidentrate}', '{$foc}')"; mysql_query($sql); if (mysql_error()) { trigger_error(mysql_error(), E_USER_ERROR); } if (mysql_affected_rows() < 1) { trigger_error("Insert failed", E_USER_ERROR); } $serviceid = mysql_insert_id(); update_contract_balance($maintid, $strNewContract, $amount, $serviceid); if ($addition_errors == 1) { // show addition error message include APPLICATION_INCPATH . 'htmlheader.inc.php'; echo $addition_errors_string; include APPLICATION_INCPATH . 'htmlfooter.inc.php'; } else { // show success message trigger('TRIGGER_NEW_CONTRACT', array('contractid' => $maintid, 'userid' => $sit[2])); html_redirect("contract_details.php?id={$maintid}"); } clear_form_data('add_contract'); } else { // show error message if errors include APPLICATION_INCPATH . 'htmlheader.inc.php'; html_redirect("contract_add.php", FALSE); } }
// External variables $incidentid = cleanvar($_REQUEST['incidentid']); $uid = cleanvar($_REQUEST['userid']); $nextaction = cleanvar($_REQUST['nextaction']); include APPLICATION_INCPATH . 'htmlheader.inc.php'; echo "<h2>{$strIncidentAdded} - {$strSummary}</h2>"; echo "<p align='center'>"; $incidentnum = "<a href=\"javascript:incident_details_window('{$incidentid}','incident{$incidentid}');\">{$strIncident} {$incidentid}</a>"; $queuename = "<strong style='color: red'>{$strActionNeeded}</strong>"; $name = user_realname($uid); printf($strHasBeenAutoMovedToX, $incidentnum, $name, $queuename); echo help_link('AutoAssignIncidents') . "</p><br /><br />"; $userphone = user_phone($userid); if ($userphone != '') { echo "<p align='center'>{$strTelephone}: {$userphone}</p>"; } $sql = "UPDATE `{$dbIncidents}` SET owner='{$uid}', lastupdated='{$now}' WHERE id='{$incidentid}'"; mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } trigger('TRIGGER_INCIDENT_ASSIGNED', array('userid' => $uid, 'incidentid' => $incidentid)); // add update $sql = "INSERT INTO `{$dbUpdates}` (incidentid, userid, type, timestamp, currentowner, currentstatus, nextaction) "; $sql .= "VALUES ('{$incidentid}', '{$sit[2]}', 'reassigning', '{$now}', '{$uid}', '1', '{$nextaction}')"; $result = mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } include APPLICATION_INCPATH . 'htmlfooter.inc.php'; }
<?php $TABLE = $_GET["trigger"]; $name = $_GET["name"]; $trigger_options = trigger_options(); $row = (array) trigger($name) + array("Trigger" => $TABLE . "_bi"); if ($_POST) { if (!$error && in_array($_POST["Timing"], $trigger_options["Timing"]) && in_array($_POST["Event"], $trigger_options["Event"]) && in_array($_POST["Type"], $trigger_options["Type"])) { // don't use drop_create() because there may not be more triggers for the same action $on = " ON " . table($TABLE); $drop = "DROP TRIGGER " . idf_escape($name) . ($jush == "pgsql" ? $on : ""); $location = ME . "table=" . urlencode($TABLE); if ($_POST["drop"]) { query_adminer_redirect($drop, $location, lang('Trigger has been dropped.')); } else { if ($name != "") { queries($drop); } queries_adminer_redirect($location, $name != "" ? lang('Trigger has been altered.') : lang('Trigger has been created.'), queries(create_trigger($on, $_POST))); if ($name != "") { queries(create_trigger($on, $row + array("Type" => reset($trigger_options["Type"])))); } } } $row = $_POST; } page_header($name != "" ? lang('Alter trigger') . ": " . h($name) : lang('Create trigger'), $error, array("table" => $TABLE)); ?> <form action="" method="post" id="form"> <table cellspacing="0">
/** * The main "auto_create" function * The function is specific to rules sent to our clients regarding the naming of * their email Subject: * For this reason the plugin is specific but not impossible to adapt * Clients send their email like this: * "Hardware [Productname] Serial number Reference" * or "Software [Softwarename] Version Reference" * or "Warranty [Productname] Serial number Reference" * This helps to simplify the creation, and detection of this function * @author Nico du toit * @return Returns the newly created incidentid to the inbopund script to * continue processing * OR returns nothing and the new update goes to the holding queue as before */ function auto_create_incidents($params) { unset($GLOBALS['plugin_reason']); $incidentid = $params['incidentid']; $contactid = $params['contactid']; $subject = $params['subject']; $decoded = $params['decoded']; $send_email = 1; global $CONFIG, $dbIncidents, $now; debug_log("incident ID : " . $incidentid . " \n Contactid: " . $contactid . "\n" . "Subject : " . $subject); if ($incidentid > 0) { return $incidentid; } if (in_array($contactid, $CONFIG['auto_create_contact_exclude'])) { debug_log("For this client : " . $contactid . " autocreate is forbidden! see the config file"); $GLOBALS['plugin_reason'] = 'Contact BLOCKED'; return; } if ($contactid < 1) { $GLOBALS['plugin_reason'] = 'Contact not in DataBase'; return; } $cc = find_cc_decoded($decoded); if (stristr($cc, $CONFIG['support_email'])) { debug_log("Support was in the copy of the email!!"); $GLOBALS['plugin_reason'] = 'Support in CC of email'; return; } debug_log("Redirecting to function checking for duplicates ... "); //Check if duplicates exists in the incidents DB $create_incident = check_for_duplicates($subject, $contactid); if ($create_incident == "NO") { debug_log("case 0: more than 1 duplicate"); $GLOBALS['plugin_reason'] = 'Possible DUPLICATE'; return; } if ($create_incident != "YES" && $create_incident != "NO") { debug_log("case 1: only 1 duplicate"); debug_log("The duplicate incidentID =: " . $create_incident); return $create_incident; } if ($create_incident == "YES") { debug_log("case 2: No duplicates found"); debug_log("Proceeding to - Auto create"); $ccemail = $cc; $origsubject = mysql_real_escape_string($subject); $subject = strtolower($subject); //Check if any of our keywords exists TODO: Need to make the keywords //configurable in the config file $warranty = preg_match("/warranty|warrantee|waranty|diagnostic/i", $subject); $hard = preg_match("/hardware|hard/i", $subject); $soft = preg_match("/soft|software/i", $subject); if ($warranty == 1 && $hard == 0 && $soft == 0) { $case = 0; debug_log("Match for Warranty in : " . $subject); } elseif ($hard == 1 && $soft == 0 && $warranty == 0) { $case = 1; debug_log("Match for Hardware in : " . $subject); } elseif ($soft == 1 && $hard == 0 && $warranty == 0) { $case = 2; debug_log("Match for Software in : " . $subject); } else { $case = 3; debug_log("NO match found for any keyword in : " . $subject); } switch ($case) { case 0: debug_log("Case type Warranty : "); $product = 9; //Hardware //$software = 41;//Warranty clam $software = find_tags_in_subject($subject); debug_log("The software tag returned is : " . $software); if (!$software || !in_array($software, $CONFIG['auto_create_warranty_include'])) { debug_log("The soft is not in the accepted warranty list or is 0 :"); $software = 41; //if no tags are found use the normal warranty claim } $servicelevel = $CONFIG['default_service_level']; $siteid = contact_siteid($contactid); $sql = "SELECT id FROM `sit_maintenance` WHERE site='{$siteid}' AND product='{$product}' "; $result = mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_WARNING); } $row = mysql_fetch_row($result); $contrid = $row[0]; //Create the incident based on the info we have $incidentid = ''; $incidentid = create_incident($origsubject, $contactid, $servicelevel, $contrid, $product, $software, $priority = 1, $owner = 0, $status = 1, $productversion = '', $productservicepacks = '', $opened = '', $lastupdated = ''); debug_log("Incident ID created : " . $incidentid); debug_log("CC address(es) found : " . $ccemail); //If we have some cc addresses, then we can update them into the case if ($ccemail) { $sql = "UPDATE `{$dbIncidents}` "; $sql .= "SET ccemail='{$ccemail}', lastupdated='{$now}' WHERE id='{$incidentid}'"; $result = mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } if (!$result) { debug_log("Update to the incident cc email succesfull!!"); } } if ($incidentid > 0) { // Insert the first SLA update, this indicates the start of an incident $sql = "INSERT INTO `sit_updates` (incidentid, userid, type, timestamp, currentowner, currentstatus, customervisibility, sla, bodytext) "; $sql .= "VALUES ('{$incidentid}', '{$sit[2]}', 'slamet', '{$now}', '{$sit[2]}', '1', 'show', 'opened','The incident is open and awaiting action.')"; mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } // Insert the first Review update, this indicates the review period of an incident has started $sql = "INSERT INTO `sit_updates` (incidentid, userid, type, timestamp, currentowner, currentstatus, customervisibility, sla, bodytext) "; $sql .= "VALUES ('{$incidentid}', '{$sit[2]}', 'reviewmet', '{$now}', '{$sit[2]}', '1', 'hide', 'opened','')"; mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } trigger('TRIGGER_INCIDENT_CREATED', array('incidentid' => $incidentid, 'sendemail' => $send_email)); debug_log("Succesfully created incident: " . $incidentid); //Insert the initial response as we see the first email as the initial response $sql = "INSERT INTO `sit_updates` (incidentid, userid, type, timestamp, currentowner, currentstatus, customervisibility, sla, bodytext) "; $sql .= "VALUES ('{$incidentid}', '{$sit[2]}', 'slamet', '{$now}', '{$owner}', '1', 'show', 'initialresponse','The Initial Response has been made by the automated tracker email.')"; mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } } //In case we have no incident ID it means the function failed - FALSE returned by function if ($incidentid == FALSE) { debug_log("Incident auto create failed: " . $subject); return; } $send_email = 1; $owner = suggest_reassign_userid($incidentid, $exceptuserid = 0); if ($owner > 0) { //Update owner in incidents $sql = "UPDATE `sit_incidents` SET owner='{$owner}', lastupdated='{$now}' WHERE id='{$incidentid}'"; mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } trigger('TRIGGER_INCIDENT_ASSIGNED', array('userid' => $owner, 'incidentid' => $incidentid)); // add update $sql = "INSERT INTO `sit_updates` (incidentid, userid, type, timestamp, currentowner, currentstatus, nextaction) "; $sql .= "VALUES ('{$incidentid}', '{$sit[2]}', 'reassigning', '{$now}', '{$owner}', '1', '{$nextaction}')"; $result = mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } debug_log("Incident re-assigned to: " . $owner); } return $incidentid; case 1: debug_log("Case type Hardware : "); $product = 9; //Hardware product //Try to recover the product name that is in the email subject (only if the sender followed the rules!) $recovprod = trim(recup_prodName($subject, '[', ']')); if ($recovprod) { $prodword = $recovprod; } elseif (!$recovprod) { //$prodword = 'HARDWARE NOT AUTOMATICALLY RECOGNISED'; $prodword = software_name(find_tags_in_subject($subject)); if (!$prodword) { $GLOBALS['plugin_reason'] = 'Hardware [Skill-Product not set]'; return; } } $sql = "SELECT LOWER(id) FROM `sit_software` WHERE name LIKE '%{$prodword}%' "; $result = mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_WARNING); } $numresults = mysql_num_rows($result); $row = mysql_fetch_row($result); //No match found if ($numresults == 0) { //Set the software to a precreated value in the DB //$software = 53; $GLOBALS['plugin_reason'] = 'Hardware [Skill-Product not set]'; return; } //Multiple matches found, take the first one //TODO: Improve this as it is not that accurate if ($numresults > 0) { $software = $row[0]; } $servicelevel = $CONFIG['default_service_level']; $siteid = contact_siteid($contactid); //Find the hardware contract for this contact $sql = "SELECT id FROM `sit_maintenance` WHERE site='{$siteid}' AND product='{$product}' "; $result = mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_WARNING); } $row = mysql_fetch_row($result); $contrid = $row[0]; /*TODO: This was not working correctly, but can be fixed i am sure... * The idea is to change the priority according to the product or skill * if ($software == 4||5||6||7||8||13||17||18||37||45||48) { $priority = 3; } else { $priority = 2; } echo "CONTRACT"; echo $contrid; echo "<br>"; //Allthese are created as priority medium - Need still to fix the above //$priority = 2;*/ $incidentid = ''; $incidentid = create_incident($origsubject, $contactid, $servicelevel, $contrid, $product, $software, $priority = 2, $owner = 0, $status = 1, $productversion = '', $productservicepacks = '', $opened = '', $lastupdated = ''); debug_log("Incident ID created : " . $incidentid); debug_log("CC address(es) found : " . $ccemail); //If we have some cc addresses, then we can update them into the case if ($ccemail) { $sql = "UPDATE `{$dbIncidents}` "; $sql .= "SET ccemail='{$ccemail}', lastupdated='{$now}' WHERE id='{$incidentid}'"; $result = mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } if (!$result) { debug_log("Update to the incident cc email succesfull!!"); } } // If we have an incident id - we can now do the updates if ($incidentid > 0) { // Insert the first SLA update, this indicates the start of an incident $sql = "INSERT INTO `sit_updates` (incidentid, userid, type, timestamp, currentowner, currentstatus, customervisibility, sla, bodytext) "; $sql .= "VALUES ('{$incidentid}', '{$sit[2]}', 'slamet', '{$now}', '{$sit[2]}', '1', 'show', 'opened','The incident is open and awaiting action.')"; mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } // Insert the first Review update, this indicates the review period of an incident has started $sql = "INSERT INTO `sit_updates` (incidentid, userid, type, timestamp, currentowner, currentstatus, customervisibility, sla, bodytext) "; $sql .= "VALUES ('{$incidentid}', '{$sit[2]}', 'reviewmet', '{$now}', '{$sit[2]}', '1', 'hide', 'opened','')"; mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } trigger('TRIGGER_INCIDENT_CREATED', array('incidentid' => $incidentid, 'sendemail' => $send_email)); debug_log("Succesfully created incident: " . $incidentid); //Insert the initial response as we see the first email as the initial response $sql = "INSERT INTO `sit_updates` (incidentid, userid, type, timestamp, currentowner, currentstatus, customervisibility, sla, bodytext) "; $sql .= "VALUES ('{$incidentid}', '{$sit[2]}', 'slamet', '{$now}', '{$owner}', '1', 'show', 'initialresponse','The Initial Response has been made by the automated tracker email.')"; mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } } //In case we have no incident ID it means the function failed - FALSE returned by function if ($incidentid == FALSE) { debug_log("Incident auto create failed: " . $subject); return; } $send_email = 1; $owner = suggest_reassign_userid($incidentid, $exceptuserid = 0); //update the Db with the suggested user to reassign to if ($owner > 0) { $sql = "UPDATE `sit_incidents` SET owner='{$owner}', lastupdated='{$now}' WHERE id='{$incidentid}'"; mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } trigger('TRIGGER_INCIDENT_ASSIGNED', array('userid' => $owner, 'incidentid' => $incidentid)); // add update $sql = "INSERT INTO `sit_updates` (incidentid, userid, type, timestamp, currentowner, currentstatus, nextaction) "; $sql .= "VALUES ('{$incidentid}', '{$sit[2]}', 'reassigning', '{$now}', '{$owner}', '1', '{$nextaction}')"; $result = mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } debug_log("Incident re-assigned to: " . $owner); } return $incidentid; case 2: debug_log("Case type Software : "); $product = 10; //Software product //Try to recover the product name that is in the email subject (only if the sender followed the rules!) $recovprod = trim(recup_prodName($subject, '[', ']')); if ($recovprod) { $prodword = $recovprod; } elseif (!$recovprod) { //$prodword = 'SOFTWARE NOT AUTOMATICALLY RECOGNISED'; $prodword = software_name(find_tags_in_subject($subject)); if (!$prodword) { $GLOBALS['plugin_reason'] = 'Software [Skill-Product not set]'; return; } } $sql = "SELECT LOWER(id) FROM `sit_software` WHERE name LIKE '%{$prodword}%' "; $result = mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_WARNING); } $numresults = mysql_num_rows($result); $row = mysql_fetch_row($result); //No match found if ($numresults == 0) { //$software = 54; $GLOBALS['plugin_reason'] = 'Software [Skill-Product not set]'; return; } //Multiple matches found, take the first one //TODO: Improve this as it is not that accurate if ($numresults > 0) { $software = $row[0]; } $servicelevel = $CONFIG['default_service_level']; $siteid = contact_siteid($contactid); //Find the software contract for this contact $sql = "SELECT id FROM `sit_maintenance` WHERE site='{$siteid}' AND product='{$product}' "; $result = mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_WARNING); } $row = mysql_fetch_row($result); $contrid = $row[0]; /*TODO: This was not working correctly, but can be fixed i am sure... * The idea is to change the priority according to the product or skill echo $contrid; echo "<br>"; if ($software == 54||36||38) { $priority = 1; } else { $priority = 2; } //Allthese are created as priority medium - Need still to fix the above //$priority = 2;*/ $incidentid = ''; $incidentid = create_incident($origsubject, $contactid, $servicelevel, $contrid, $product, $software, $priority = 2, $owner = 0, $status = 1, $productversion = '', $productservicepacks = '', $opened = '', $lastupdated = ''); debug_log("Incident ID created : " . $incidentid); debug_log("CC address(es) found : " . $ccemail); //If we have some cc addresses, then we can update them into the case if ($ccemail) { $sql = "UPDATE `{$dbIncidents}` "; $sql .= "SET ccemail='{$ccemail}', lastupdated='{$now}' WHERE id='{$incidentid}'"; $result = mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } if (!$result) { debug_log("Update to the incident cc email succesfull!!"); } } if ($incidentid > 0) { // Insert the first SLA update, this indicates the start of an incident $sql = "INSERT INTO `sit_updates` (incidentid, userid, type, timestamp, currentowner, currentstatus, customervisibility, sla, bodytext) "; $sql .= "VALUES ('{$incidentid}', '{$sit[2]}', 'slamet', '{$now}', '{$sit[2]}', '1', 'show', 'opened','The incident is open and awaiting action.')"; mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } // Insert the first Review update, this indicates the review period of an incident has started $sql = "INSERT INTO `sit_updates` (incidentid, userid, type, timestamp, currentowner, currentstatus, customervisibility, sla, bodytext) "; $sql .= "VALUES ('{$incidentid}', '{$sit[2]}', 'reviewmet', '{$now}', '{$sit[2]}', '1', 'hide', 'opened','')"; mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } trigger('TRIGGER_INCIDENT_CREATED', array('incidentid' => $incidentid, 'sendemail' => $send_email)); debug_log("Succesfully created incident: " . $incidentid); //Insert the initial response as we see the first email as the initial response $sql = "INSERT INTO `sit_updates` (incidentid, userid, type, timestamp, currentowner, currentstatus, customervisibility, sla, bodytext) "; $sql .= "VALUES ('{$incidentid}', '{$sit[2]}', 'slamet', '{$now}', '{$owner}', '1', 'show', 'initialresponse','The Initial Response has been made by the automated tracker email.')"; mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } } //In case we have no incident ID it means the function failed - FALSE returned by function if ($incidentid == FALSE) { debug_log("Incident auto create failed: " . $subject); return; } $send_email = 1; $owner = suggest_reassign_userid($incidentid, $exceptuserid = 0); //Update the Db with the suggested owner if ($owner > 0) { $sql = "UPDATE `sit_incidents` SET owner='{$owner}', lastupdated='{$now}' WHERE id='{$incidentid}'"; mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } trigger('TRIGGER_INCIDENT_ASSIGNED', array('userid' => $owner, 'incidentid' => $incidentid)); // add update $sql = "INSERT INTO `sit_updates` (incidentid, userid, type, timestamp, currentowner, currentstatus, nextaction) "; $sql .= "VALUES ('{$incidentid}', '{$sit[2]}', 'reassigning', '{$now}', '{$owner}', '1', '{$nextaction}')"; $result = mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } debug_log("Incident re-assigned to: " . $owner); } return $incidentid; case 3: $GLOBALS['plugin_reason'] = 'INCORRECTLY formatted'; debug_log("There was no reference found for the correct skill in: " . $subject); return; } } }
if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } $newuserid = mysql_insert_id(); // Create permissions (set to none) $sql = "SELECT * FROM `{$dbPermissions}`"; $result = mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_WARNING); } while ($perm = mysql_fetch_object($result)) { $psql = "INSERT INTO `{$dbUserPermissions}` (userid, permissionid, granted) "; $psql .= "VALUES ('{$newuserid}', '{$perm->id}', 'false')"; mysql_query($psql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } } if (!$result) { echo "<p class='error'>{$strAdditionFail}</p>\n"; } else { setup_user_triggers($newuserid); trigger('TRIGGER_NEW_USER', array('userid' => $newuserid)); html_redirect("manage_users.php#userid{$newuserid}"); } clear_form_data('add_user'); clear_form_errors('add_user'); } else { html_redirect($_SERVER['PHP_SELF'], FALSE); } }