public function update_check() { $config =& singleton::get(__NAMESPACE__ . '\\config'); $apptrack =& singleton::get(__NAMESPACE__ . '\\apptrack'); $send_data['application_id'] = 1; $send_data['version'] = $config->get('program_version'); $data = $apptrack->send($send_data); if (!empty($data)) { $config->set('last_update_response', $data); return true; } else { $log =& singleton::get(__NAMESPACE__ . '\\log'); $log_array['event_severity'] = 'warning'; $log_array['event_number'] = E_USER_WARNING; $log_array['event_description'] = 'Unable to contact update server.'; $log_array['event_file'] = __FILE__; $log_array['event_file_line'] = __LINE__; $log_array['event_type'] = 'update_check'; $log_array['event_source'] = 'cron'; $log_array['event_version'] = '1'; $log_array['log_backtrace'] = false; $log->add($log_array); return false; } }
public function get($name) { $error =& singleton::get(__NAMESPACE__ . '\\error'); if (isset($this->language_array[$name])) { //return '試験'; //return '試験' . $this->language_array[$name]; return $this->language_array[$name]; } else { //$error->create(array('type' => 'language_item_missing', 'message' => 'Unable to find language item "'.$name.'".')); return $name; } }
public function optimise_tables() { global $db; $tables =& singleton::get(__NAMESPACE__ . '\\tables'); $log =& singleton::get(__NAMESPACE__ . '\\log'); $log_array['event_severity'] = 'notice'; $log_array['event_number'] = E_USER_NOTICE; $log_array['event_description'] = 'Optimising Tables'; $log_array['event_file'] = __FILE__; $log_array['event_file_line'] = __LINE__; $log_array['event_type'] = 'optimise_tables'; $log_array['event_source'] = 'db_maintenance'; $log_array['event_version'] = '1'; $log_array['log_backtrace'] = false; $log->add($log_array); $optimise_tables = ''; foreach ($tables->get() as $value => $index) { $optimise_tables .= $index . ','; } $optimise_tables = substr($optimise_tables, 0, strlen($optimise_tables) - 1); $query = 'OPTIMIZE TABLE ' . $optimise_tables; foreach ($db->query($query, database::FETCH_ASSOC) as $row) { if ($row['Msg_type'] == 'error') { $number = E_USER_WARNING; $type = 'warning'; } else { $number = E_USER_NOTICE; $type = 'notice'; } $log_array['event_severity'] = $type; $log_array['event_number'] = $number; $log_array['event_description'] = 'Table "' . $row['Table'] . '"<br />Message "' . $row['Msg_text'] . '"'; $log_array['event_file'] = __FILE__; $log_array['event_file_line'] = __LINE__; $log_array['event_type'] = 'optimise_tables'; $log_array['event_source'] = 'db_maintenance'; $log_array['event_version'] = '1'; $log_array['log_backtrace'] = false; $log->add($log_array); } $log_array['event_severity'] = 'notice'; $log_array['event_number'] = E_USER_NOTICE; $log_array['event_description'] = 'Optimising Tables Complete'; $log_array['event_file'] = __FILE__; $log_array['event_file_line'] = __LINE__; $log_array['event_type'] = 'optimise_tables'; $log_array['event_source'] = 'db_maintenance'; $log_array['event_version'] = '1'; $log_array['log_backtrace'] = false; $log->add($log_array); }
public function send($array) { $log =& singleton::get(__NAMESPACE__ . '\\log'); $array['token'] = $this->app_key; /* Limit to 512 chars as per pushover limit. */ $remove = 0; if (isset($array['title'])) { $remove = (int) strlen($array['title']); } if (isset($array['message'])) { $array['message'] = substr($array['message'], 0, 512 - $remove); } $options = array('http' => array('user_agent' => user_agent(), 'timeout' => 5, 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query($array))); $context = stream_context_create($options); $result = @file_get_contents($this->api_url, false, $context); if ($result) { $return_data = json_decode($result, true); if ($return_data['status'] == 1) { return true; } else { $larray['event_severity'] = 'error'; $larray['event_number'] = E_USER_ERROR; $larray['event_description'] = 'Unable to send pushover message.'; $larray['event_file'] = __FILE__; $larray['event_file_line'] = __LINE__; $larray['event_type'] = 'send'; $larray['event_source'] = 'pushover'; $larray['event_version'] = '1'; $larray['log_backtrace'] = true; $log->add($larray); } } else { $larray['event_severity'] = 'error'; $larray['event_number'] = E_USER_ERROR; $larray['event_description'] = 'Unable to send pushover message.'; $larray['event_file'] = __FILE__; $larray['event_file_line'] = __LINE__; $larray['event_type'] = 'send'; $larray['event_source'] = 'pushover'; $larray['event_version'] = '1'; $larray['log_backtrace'] = true; $log->add($larray); } return false; }
private function can_view($array) { $auth =& singleton::get(__NAMESPACE__ . '\\auth'); $tickets =& singleton::get(__NAMESPACE__ . '\\tickets'); $user_level = (int) $auth->get('user_level'); switch ($user_level) { case 6: //admin break; case 5: //moderator $get_array['department_or_assigned_or_user_id'] = $auth->get('id'); break; case 4: //staff member $get_array['department_or_assigned_or_user_id'] = $auth->get('id'); break; case 3: //user $get_array['assigned_or_user_id'] = $auth->get('id'); break; case 2: //global moderator break; default: //sub $get_array['user_id'] = $auth->get('id'); break; } $get_array['count'] = true; $get_array['id'] = (int) $array['id']; $result = $tickets->get($get_array); if (!empty($result) && $result[0]['count'] != 0) { return true; } else { return false; } }
function display() { $config =& singleton::get(__NAMESPACE__ . '\\config'); $language =& singleton::get(__NAMESPACE__ . '\\language'); header("Content-type: image/png"); if (isset($this->text) && !empty($this->text)) { $capture_text = $this->text; } else { $capture_text = $language->get('Error'); } $string = strtoupper($capture_text); $r = rand(0, 150); $g = rand(0, 150); $b = rand(0, 150); $im = imagecreatefrompng(THEMES . '/' . CURRENT_THEME . '/images/captcha_background.png'); $colour = imagecolorallocate($im, $r, $g, $b); $size = rand(20, 25); $angle = rand(0, 3); $left = rand(5, 17); $bottomleft = 38; imagettftext($im, $size, $angle, $left, $bottomleft, $colour, SYSTEM . "/fonts/delicious.otf", $string); imagepng($im); imagedestroy($im); }
//message_notes $ticket_custom_fields =& singleton::get(__NAMESPACE__ . '\\ticket_custom_fields'); //pushover $pushover =& singleton::get(__NAMESPACE__ . '\\pushover'); //users_to_departments $users_to_departments =& singleton::get(__NAMESPACE__ . '\\users_to_departments'); //db_maintenance $db_maintenance =& singleton::get(__NAMESPACE__ . '\\db_maintenance'); require FUNCTIONS . '/default_tasks.php'; /** * * URL Handling Code. Everything is redirected with the .htaccess file to index.php?url= * */ if (isset($_GET['url'])) { $input_url = $_GET['url']; } else { $input_url = ''; } $url =& singleton::get(__NAMESPACE__ . '\\url', array('url' => $input_url)); unset($input_url); $auth->load(); //html purifier include LIB . '/htmlpurifier/HTMLPurifier.auto.php'; $htmlpurifier_config = \HTMLPurifier_Config::createDefault(); //default html is set to XHTML 1.1 //$htmlpurifier_config->set('Core.Encoding', 'XHTML 1.1'); //create the class we are going to use. $purifier =& singleton::get('HTMLPurifier', $htmlpurifier_config); $plugins->load(); $plugins->run('loader');
function disable($plugin_name) { $config =& singleton::get(__NAMESPACE__ . '\\config'); $log =& singleton::get(__NAMESPACE__ . '\\log'); if (in_array($plugin_name, $this->installed_plugins)) { $key = array_search($plugin_name, $this->installed_plugins); unset($this->installed_plugins[$key]); $this->installed_plugins = array_values($this->installed_plugins); $log_array['event_severity'] = 'notice'; $log_array['event_number'] = E_USER_NOTICE; $log_array['event_description'] = 'Plugin Disabled "' . $plugin_name . '"'; $log_array['event_file'] = __FILE__; $log_array['event_file_line'] = __LINE__; $log_array['event_type'] = 'disable'; $log_array['event_source'] = 'plugins'; $log_array['event_version'] = '1'; $log_array['log_backtrace'] = false; $log->add($log_array); $config->set('plugin_data', $this->installed_plugins); } }
public function new_user($array) { $mailer =& singleton::get(__NAMESPACE__ . '\\mailer'); $config =& singleton::get(__NAMESPACE__ . '\\config'); if (is_array($array)) { $template_subject = $config->get('notification_new_user_subject'); $subject_temp = str_replace('#SITE_NAME#', $config->get('name'), $template_subject); $subject_temp = str_replace('#USER_FULLNAME#', $array['name'], $subject_temp); $subject_temp = str_replace('#USER_NAME#', $array['username'], $subject_temp); $subject_temp = str_replace('#USER_PASSWORD#', $array['password'], $subject_temp); $subject_temp = str_replace('#USER_EMAIL#', $array['email'], $subject_temp); $subject_temp = str_replace('#SITE_ADDRESS#', $config->get('address'), $subject_temp); $email_array['subject'] = $subject_temp; $template_body = $config->get('notification_new_user_body'); $body_temp = str_replace('#USER_FULLNAME#', $array['name'], $template_body); $body_temp = str_replace('#USER_NAME#', $array['username'], $body_temp); $body_temp = str_replace('#USER_PASSWORD#', $array['password'], $body_temp); $body_temp = str_replace('#USER_EMAIL#', $array['email'], $body_temp); $body_temp = str_replace('#SITE_NAME#', $config->get('name'), $body_temp); $body_temp = str_replace('#SITE_ADDRESS#', $config->get('address'), $body_temp); $email_array['body'] = $body_temp; $email_array['html'] = true; $email_array['to']['to'] = $array['email']; $email_array['to']['to_name'] = $array['name']; if (isset($array['pop_account_id'])) { $email_array['pop_account_id'] = $array['pop_account_id']; } $mailer->queue_email($email_array); return true; } else { return false; } }
function save($queue) { global $db; $tables =& singleton::get(__NAMESPACE__ . '\\tables'); $error =& singleton::get(__NAMESPACE__ . '\\error'); $site_id = SITE_ID; $query = "UPDATE {$tables->queue} SET retry = :retry WHERE id = :id AND site_id = :site_id"; try { $stmt = $db->prepare($query); } catch (Exception $e) { $error->create(array('type' => 'sql_prepare_error', 'message' => $e->getMessage())); } $stmt->bindParam(':site_id', $site_id, database::PARAM_STR); $stmt->bindParam(':retry', $queue['retry'], database::PARAM_INT); $stmt->bindParam(':id', $queue['id'], database::PARAM_INT); try { $stmt->execute(); } catch (\Exception $e) { $error->create(array('type' => 'sql_execute_error', 'message' => $e->getMessage())); } return true; }
function delete($array) { global $db; $tables =& singleton::get(__NAMESPACE__ . '\\tables'); $error =& singleton::get(__NAMESPACE__ . '\\error'); $site_id = SITE_ID; //delete ticket $query = "DELETE FROM {$this->table_name} WHERE site_id = :site_id"; if (isset($array['columns'])) { foreach ($array['columns'] as $index => $value) { if (in_array($index, $this->allowed_columns)) { $query .= ' AND ' . $index . ' = :' . $index; unset($index); unset($value); } } } if (isset($array['id'])) { $query .= " AND id = :id"; } //echo $query; try { $stmt = $db->prepare($query); } catch (\Exception $e) { $error->create(array('type' => 'sql_prepare_error', 'message' => $e->getMessage())); } $stmt->bindParam(':site_id', $site_id, database::PARAM_INT); if (isset($array['id'])) { $stmt->bindParam(':id', $array['id'], database::PARAM_INT); } if (isset($array['columns'])) { foreach ($array['columns'] as $index => $value) { if (in_array($index, $this->allowed_columns)) { $stmt->bindParam(':' . $index, $value); unset($index); unset($value); } } } try { $stmt->execute(); } catch (\Exception $e) { $error->create(array('type' => 'sql_execute_error', 'message' => $e->getMessage())); } }
function delete_group($array = NULL) { global $db; if (!isset($array['id'])) { return false; } $error =& singleton::get(__NAMESPACE__ . '\\error'); $log =& singleton::get(__NAMESPACE__ . '\\log'); $tables =& singleton::get(__NAMESPACE__ . '\\tables'); $auth =& singleton::get(__NAMESPACE__ . '\\auth'); $config =& singleton::get(__NAMESPACE__ . '\\config'); $site_id = SITE_ID; $query = "DELETE FROM {$tables->ticket_field_values} WHERE site_id = :site_id"; if (isset($array['id'])) { $query .= " AND ticket_field_group_id = :id"; } try { $stmt = $db->prepare($query); } catch (\Exception $e) { $error->create(array('type' => 'sql_prepare_error', 'message' => $e->getMessage())); } $stmt->bindParam(':site_id', $site_id, database::PARAM_INT); if (isset($array['id'])) { $stmt->bindParam(':id', $array['id'], database::PARAM_INT); } try { $stmt->execute(); } catch (\Exception $e) { $error->create(array('type' => 'sql_execute_error', 'message' => $e->getMessage())); } $query = "DELETE FROM {$tables->ticket_fields} WHERE site_id = :site_id"; if (isset($array['id'])) { $query .= " AND ticket_field_group_id = :id"; } try { $stmt = $db->prepare($query); } catch (\Exception $e) { $error->create(array('type' => 'sql_prepare_error', 'message' => $e->getMessage())); } $stmt->bindParam(':site_id', $site_id, database::PARAM_INT); if (isset($array['id'])) { $stmt->bindParam(':id', $array['id'], database::PARAM_INT); } try { $stmt->execute(); } catch (\Exception $e) { $error->create(array('type' => 'sql_execute_error', 'message' => $e->getMessage())); } $query = "DELETE FROM {$tables->ticket_field_group} WHERE site_id = :site_id"; if (isset($array['id'])) { $query .= " AND id = :id"; } try { $stmt = $db->prepare($query); } catch (\Exception $e) { $error->create(array('type' => 'sql_prepare_error', 'message' => $e->getMessage())); } $stmt->bindParam(':site_id', $site_id, database::PARAM_INT); if (isset($array['id'])) { $stmt->bindParam(':id', $array['id'], database::PARAM_INT); } try { $stmt->execute(); } catch (\Exception $e) { $error->create(array('type' => 'sql_execute_error', 'message' => $e->getMessage())); } }
private function dbsv_18() { global $db; $config =& singleton::get(__NAMESPACE__ . '\\config'); $tables =& singleton::get(__NAMESPACE__ . '\\tables'); $error =& singleton::get(__NAMESPACE__ . '\\error'); $notifications =& singleton::get(__NAMESPACE__ . '\\notifications'); $query = "ALTER TABLE `{$tables->ticket_notes}` ADD `private` INT( 1 ) UNSIGNED NOT NULL DEFAULT '0'"; try { $db->query($query); } catch (\Exception $e) { $error->create(array('type' => 'sql_execute_error', 'message' => $e->getMessage())); } $query = "ALTER TABLE `{$tables->ticket_notes}` ADD INDEX `private` ( `private` )"; try { $db->query($query); } catch (\Exception $e) { $error->create(array('type' => 'sql_execute_error', 'message' => $e->getMessage())); } $config->add('notification_new_user_subject', ''); $config->add('notification_new_user_body', ''); $notifications->reset_new_user_notification(); $cron_intervals = $config->get('cron_intervals'); $cron_intervals[] = array('name' => 'every_two_minutes', 'description' => 'Every Two Minutes', 'next_run' => '0000-00-00 00:00:00', 'frequency' => '120'); $config->set('cron_intervals', $cron_intervals); $config->add('log_limit', '100000'); $config->set('database_version', 18); $config->set('program_version', '2.5'); }
/** * Returns an HTML string while stripping out bad HTML * * @param string $string The HTML to make safe * @return string The safe HTML */ function html_output($string) { $purifier =& singleton::get('HTMLPurifier'); return $purifier->purify($string); }
public function read($array) { global $db; $tables =& singleton::get(__NAMESPACE__ . '\\tables'); $error =& singleton::get(__NAMESPACE__ . '\\error'); $site_id = SITE_ID; $query = "DELETE FROM `{$tables->message_unread}` WHERE message_id = :message_id AND site_id = :site_id"; if (isset($array['user_id'])) { $query .= " AND user_id = :user_id"; } try { $stmt = $db->prepare($query); } catch (\PDOException $e) { $error->create(array('type' => 'sql_prepare_error', 'message' => $e->getMessage())); } if (isset($array['user_id'])) { $stmt->bindParam(':user_id', $array['user_id'], database::PARAM_INT); } $stmt->bindParam(':message_id', $array['message_id'], database::PARAM_INT); $stmt->bindParam(':site_id', $site_id, database::PARAM_INT); try { $stmt->execute(); } catch (\PDOException $e) { $error->create(array('type' => 'sql_execute_error', 'message' => $e->getMessage())); } return true; }
function display_custom_field_forms() { $ticket_custom_fields =& singleton::get(__NAMESPACE__ . '\\ticket_custom_fields'); $custom_field_groups = $ticket_custom_fields->get_groups(array('enabled' => 1, 'client_modify' => 1)); foreach ($custom_field_groups as $custom_field_group) { ?> <p><?php echo safe_output($custom_field_group['name']); ?> <br /> <?php if ($custom_field_group['type'] == 'dropdown') { ?> <?php $fields = $ticket_custom_fields->get_fields(array('ticket_field_group_id' => $custom_field_group['id'])); ?> <select name="field-<?php echo safe_output($custom_field_group['id']); ?> "> <?php foreach ($fields as $field) { ?> <option value="<?php echo safe_output($field['id']); ?> "<?php if (isset($_POST['field-' . safe_output($custom_field_group['id'])]) && $field['id'] == $_POST['field-' . safe_output($custom_field_group['id'])]) { echo ' selected="selected"'; } ?> ><?php echo safe_output($field['value']); ?> </option> <?php } ?> </select> <?php } else { if ($custom_field_group['type'] == 'textinput') { ?> <input type="text" name="field-<?php echo safe_output($custom_field_group['id']); ?> " value="<?php if (isset($_POST['field-' . safe_output($custom_field_group['id'])])) { echo safe_output($_POST['field-' . safe_output($custom_field_group['id'])]); } ?> " size="50" /> <?php } else { if ($custom_field_group['type'] == 'textarea') { ?> <div id="no_underline"> <textarea class="wysiwyg_enabled" name="field-<?php echo safe_output($custom_field_group['id']); ?> " cols="80" rows="12"><?php if (isset($_POST['field-' . safe_output($custom_field_group['id'])])) { echo safe_output($_POST['field-' . safe_output($custom_field_group['id'])]); } ?> </textarea> </div> <?php } } } ?> </p> <?php } }
public function count_message($array = NULL) { global $db; $tables =& singleton::get(__NAMESPACE__ . '\\tables'); $error =& singleton::get(__NAMESPACE__ . '\\error'); $site_id = SITE_ID; $query = "SELECT count(*) AS `count` FROM {$tables->pop_messages} WHERE site_id = :site_id"; if (isset($array['id'])) { $query .= " AND id = :id"; } if (isset($array['message_id'])) { $query .= " AND message_id = :message_id"; } try { $stmt = $db->prepare($query); } catch (\PDOException $e) { $error->create(array('type' => 'sql_prepare_error', 'message' => $e->getMessage())); } $stmt->bindParam(':site_id', $site_id); if (isset($array['id'])) { $id = $array['id']; $stmt->bindParam(':id', $id, database::PARAM_INT); } if (isset($array['message_id'])) { $message_id = $array['message_id']; $stmt->bindParam(':message_id', $message_id, database::PARAM_INT); } try { $stmt->execute(); } catch (\PDOException $e) { $error->create(array('type' => 'sql_execute_error', 'message' => $e->getMessage())); } $count = $stmt->fetch(database::FETCH_ASSOC); return (int) $count['count']; }
public function delete($array) { global $db; $error =& singleton::get(__NAMESPACE__ . '\\error'); $tables =& singleton::get(__NAMESPACE__ . '\\tables'); $site_id = SITE_ID; if (!isset($array['id'])) { return false; } //remove attached files from objects //tickets $query = "DELETE FROM {$tables->files_to_tickets} WHERE file_id = :file_id AND site_id = :site_id"; try { $stmt = $db->prepare($query); } catch (\Exception $e) { $error->create(array('type' => 'sql_prepare_error', 'message' => $e->getMessage())); } $stmt->bindParam(':site_id', $site_id, database::PARAM_INT); $stmt->bindParam(':file_id', $array['id'], database::PARAM_INT); try { $stmt->execute(); } catch (\Exception $e) { $error->create(array('type' => 'sql_execute_error', 'message' => $e->getMessage())); } //delete file $files = $this->get(array('id' => $array['id'], 'limit' => 1)); if (!empty($files)) { $file_name = $this->upload_path . $files[0]['uuid'] . '.' . $files[0]['extension']; unlink($file_name); } $query = "DELETE FROM {$table->storage} WHERE id = :id AND site_id = :site_id"; try { $stmt = $db->prepare($query); } catch (\Exception $e) { $error->create(array('type' => 'sql_prepare_error', 'message' => $e->getMessage())); } $stmt->bindParam(':id', $array['id'], database::PARAM_INT); $stmt->bindParam(':site_id', $site_id, database::PARAM_INT); try { $stmt->execute(); } catch (\Exception $e) { $error->create(array('type' => 'sql_execute_error', 'message' => $e->getMessage())); } return true; }
function create_reset_key($array) { global $db; $notifications =& singleton::get(__NAMESPACE__ . '\\notifications'); if (isset($array['username'])) { $users_array = $this->get(array('username' => $array['username'], 'authentication_id' => 1, 'allow_login' => 1)); } else { return false; } if (count($users_array) == 1) { $id = (int) $users_array[0]['id']; $reset_key = rand_str(); //lasts 12 hours $reset_expiry = datetime(43200); $this->edit(array('id' => $id, 'reset_key' => $reset_key, 'reset_expiry' => $reset_expiry)); $notif_array['reset_key'] = $reset_key; $notif_array['reset_expiry'] = $reset_expiry; $notif_array['user'] = $users_array[0]; $notifications->password_reset($notif_array); return $reset_key; } else { return false; } }
/** * Returns the user agent for use when calling external web sites and services * * @return string The user agent (i.e. Dalegroup STS/1.1) */ function user_agent() { $config =& singleton::get(__NAMESPACE__ . '\\config'); $program_version = $config->get('program_version'); return 'Dalegroup STS/' . $program_version; }
public function send_email($array) { $config =& singleton::get(__NAMESPACE__ . '\\config'); $log =& singleton::get(__NAMESPACE__ . '\\log'); $pop_accounts =& singleton::get(__NAMESPACE__ . '\\pop_accounts'); $smtp_accounts =& singleton::get(__NAMESPACE__ . '\\smtp_accounts'); try { //clear any current info $this->phpmailer->ClearAllRecipients(); $this->phpmailer->ClearAttachments(); $this->phpmailer->From = 'do_not_reply@' . $config->get('domain'); $found_smtp_account = false; if (isset($array['pop_account_id']) && !empty($array['pop_account_id'])) { $pop_array = $pop_accounts->get(array('id' => $array['pop_account_id'], 'get_other_data' => true)); if (!empty($pop_array) && !empty($pop_array[0]['smtp_hostname']) && $pop_array[0]['smtp_enabled'] == 1) { $smtp['hostname'] = $pop_array[0]['smtp_hostname']; $smtp['port'] = $pop_array[0]['smtp_port']; $smtp['tls'] = $pop_array[0]['smtp_tls']; $smtp['username'] = $pop_array[0]['smtp_username']; $smtp['password'] = decode($pop_array[0]['smtp_password']); $smtp['authentication'] = $pop_array[0]['smtp_authentication']; $smtp['email_address'] = $pop_array[0]['smtp_email_address']; $found_smtp_account = true; } } else { if (isset($array['smtp_account_id']) && !empty($array['smtp_account_id'])) { $smtp_array = $smtp_accounts->get(array('id' => $array['smtp_account_id'])); if (!empty($smtp_array) && !empty($smtp_array[0]['hostname']) && $smtp_array[0]['enabled'] == 1) { $smtp['hostname'] = $smtp_array[0]['hostname']; $smtp['port'] = $smtp_array[0]['port']; $smtp['tls'] = $smtp_array[0]['tls']; $smtp['username'] = $smtp_array[0]['username']; $smtp['password'] = decode($smtp_array[0]['password']); $smtp['authentication'] = $smtp_array[0]['authentication']; $smtp['email_address'] = $smtp_array[0]['email_address']; $found_smtp_account = true; } } } if (!$found_smtp_account) { $smtp_array = $smtp_accounts->get(array('id' => $config->get('default_smtp_account'))); if (!empty($smtp_array) && !empty($smtp_array[0]['hostname']) && $smtp_array[0]['enabled'] == 1) { $smtp['hostname'] = $smtp_array[0]['hostname']; $smtp['port'] = $smtp_array[0]['port']; $smtp['tls'] = $smtp_array[0]['tls']; $smtp['username'] = $smtp_array[0]['username']; $smtp['password'] = decode($smtp_array[0]['password']); $smtp['authentication'] = $smtp_array[0]['authentication']; $smtp['email_address'] = $smtp_array[0]['email_address']; $found_smtp_account = true; } } if ($found_smtp_account) { //what server to send the email to $this->phpmailer->Host = $smtp['hostname']; $this->phpmailer->Mailer = 'smtp'; //setup authentication if required if ($smtp['authentication']) { $this->phpmailer->SMTPAuth = true; // turn on SMTP authentication $this->phpmailer->Username = $smtp['username']; $this->phpmailer->Password = $smtp['password']; } if ($smtp['tls']) { $this->phpmailer->SMTPSecure = 'tls'; } $this->phpmailer->Port = (int) $smtp['port']; //setup the basic email stuff if (isset($array['from'])) { $this->phpmailer->From = $array['from']; } else { if (!empty($smtp['email_address'])) { $this->phpmailer->From = $smtp['email_address']; } } } else { $this->phpmailer->Mailer = 'mail'; if (isset($array['from'])) { $this->phpmailer->From = $array['from']; } } //increase the default timeout to 15 seconds $this->phpmailer->Timeout = 15; $this->phpmailer->CharSet = 'utf-8'; if (isset($array['html']) && $array['html'] == true) { $this->phpmailer->IsHTML(true); } if (isset($array['from_name'])) { $this->phpmailer->FromName = $array['from_name']; } else { $this->phpmailer->FromName = $config->get('name'); } $this->phpmailer->Subject = $array['subject']; $this->phpmailer->Body = $array['body']; if (isset($array['to']) && is_array($array['to'])) { if (!empty($array['to']['to'])) { $this->phpmailer->AddAddress($array['to']['to'], $array['to']['to_name']); } } //add multiple files if (isset($array['file']) && is_array($array['file'])) { foreach ($array['file'] as $file) { if (file_exists($file['file'])) { $this->phpmailer->AddAttachment($file['file'], $file['file_name']); } } } //add multiple files via a string (I haven't really tested this yet) if (isset($array['string_file']) && is_array($array['string_file'])) { foreach ($array['string_file'] as $string) { $this->phpmailer->AddStringAttachment($string['string'], $string['string_name']); } } //let's try and send the email now $this->phpmailer->Send(); $array['event_severity'] = 'notice'; $array['event_number'] = E_USER_NOTICE; if (isset($array['to']) && is_array($array['to'])) { $array['event_description'] = 'Email sent to "' . safe_output($array['to']['to']) . '" from "' . $this->phpmailer->From . '"'; } else { $array['event_description'] = 'Email sent from "' . $this->phpmailer->From . '"'; } $array['event_file'] = __FILE__; $array['event_file_line'] = __LINE__; $array['event_type'] = 'email_sent'; $array['event_source'] = 'mailer'; $array['event_version'] = '1'; $array['log_backtrace'] = false; $log->add($array); return true; } catch (\phpmailerException $e) { $array['event_severity'] = 'warning'; $array['event_number'] = E_USER_WARNING; $array['event_description'] = $e->errorMessage(); $array['event_file'] = __FILE__; $array['event_file_line'] = __LINE__; $array['event_type'] = 'email_not_sent'; $array['event_source'] = 'mailer'; $array['event_version'] = '1'; $array['log_backtrace'] = true; $log->add($array); return false; } catch (\Exception $e) { $array['event_severity'] = 'warning'; $array['event_number'] = E_USER_WARNING; $array['event_description'] = $e->getMessage(); $array['event_file'] = __FILE__; $array['event_file_line'] = __LINE__; $array['event_type'] = 'email_not_sent'; $array['event_source'] = 'mailer'; $array['event_version'] = '1'; $array['log_backtrace'] = true; $log->add($array); return false; } }
function delete($array) { global $db; $error =& singleton::get(__NAMESPACE__ . '\\error'); $tables =& singleton::get(__NAMESPACE__ . '\\tables'); $log =& singleton::get(__NAMESPACE__ . '\\log'); $site_id = SITE_ID; $query = "DELETE FROM {$tables->smtp_accounts} WHERE id = :id AND site_id = :site_id"; try { $stmt = $db->prepare($query); } catch (\Exception $e) { $error->create(array('type' => 'sql_prepare_error', 'message' => $e->getMessage())); } $id = $array['id']; $stmt->bindParam(':id', $id, database::PARAM_INT); $stmt->bindParam(':site_id', $site_id, database::PARAM_INT); try { $stmt->execute(); } catch (\Exception $e) { $error->create(array('type' => 'sql_execute_error', 'message' => $e->getMessage())); } $log_array['event_severity'] = 'notice'; $log_array['event_number'] = E_USER_NOTICE; $log_array['event_description'] = 'SMTP Account Deleted'; $log_array['event_file'] = __FILE__; $log_array['event_file_line'] = __LINE__; $log_array['event_type'] = 'delete'; $log_array['event_source'] = 'smtp_accounts'; $log_array['event_version'] = '1'; $log_array['log_backtrace'] = false; $log->add($log_array); return true; }
function delete($array = NULL) { global $db; $tables =& singleton::get(__NAMESPACE__ . '\\tables'); $error =& singleton::get(__NAMESPACE__ . '\\error'); $log =& singleton::get(__NAMESPACE__ . '\\log'); $site_id = SITE_ID; //delete user permissions if (isset($array['id'])) { $query = "DELETE FROM {$tables->users_to_departments} WHERE site_id = :site_id AND department_id = :department_id"; try { $stmt = $db->prepare($query); } catch (\PDOException $e) { $error->create(array('type' => 'sql_prepare_error', 'message' => $e->getMessage())); } $stmt->bindParam(':site_id', $site_id, database::PARAM_INT); $stmt->bindParam(':department_id', $array['id'], database::PARAM_INT); try { $stmt->execute(); } catch (\PDOException $e) { $error->create(array('type' => 'sql_execute_error', 'message' => $e->getMessage())); } } //delete ticket departments $query = "DELETE FROM {$tables->ticket_departments} WHERE site_id = :site_id"; if (isset($array['id'])) { $query .= " AND id = :id"; } if (isset($array['enabled'])) { $query .= " AND enabled = :enabled"; } try { $stmt = $db->prepare($query); } catch (\PDOException $e) { $error->create(array('type' => 'sql_prepare_error', 'message' => $e->getMessage())); } $stmt->bindParam(':site_id', $site_id, database::PARAM_INT); if (isset($array['id'])) { $stmt->bindParam(':id', $array['id'], database::PARAM_INT); } if (isset($array['enabled'])) { $stmt->bindParam(':enabled', $array['enabled'], database::PARAM_INT); } try { $stmt->execute(); } catch (\PDOException $e) { $error->create(array('type' => 'sql_execute_error', 'message' => $e->getMessage())); } $log_array['event_severity'] = 'notice'; $log_array['event_number'] = E_USER_NOTICE; $log_array['event_description'] = 'Ticket Department Deleted ID ' . safe_output($array['id']); $log_array['event_file'] = __FILE__; $log_array['event_file_line'] = __LINE__; $log_array['event_type'] = 'delete'; $log_array['event_source'] = 'ticket_departments'; $log_array['event_version'] = '1'; $log_array['log_backtrace'] = false; $log->add($log_array); }
public function prune() { global $db; $tables =& singleton::get(__NAMESPACE__ . '\\tables'); $error =& singleton::get(__NAMESPACE__ . '\\error'); $config =& singleton::get(__NAMESPACE__ . '\\config'); $log =& singleton::get(__NAMESPACE__ . '\\log'); $site_id = SITE_ID; $max_logs = (int) $config->get('log_limit'); if ($max_logs > 0) { /* Get Total Events */ $query = "SELECT count(*) as `count` FROM {$tables->events} WHERE site_id = :site_id"; try { $stmt = $db->prepare($query); } catch (\Exception $e) { $error->create(array('type' => 'sql_prepare_error', 'message' => $e->getMessage())); } $stmt->bindParam(':site_id', $site_id, database::PARAM_INT); try { $stmt->execute(); } catch (\Exception $e) { $error->create(array('type' => 'sql_execute_error', 'message' => $e->getMessage())); } $count_return = $stmt->fetchAll(database::FETCH_ASSOC); $logs_count = (int) $count_return[0]['count']; if ($logs_count > $max_logs) { $events_to_delete = $logs_count - $max_logs; $events_to_delete = (int) $events_to_delete; $event_delete_query = "DELETE FROM {$tables->events} WHERE site_id = :site_id ORDER BY id LIMIT {$events_to_delete}"; try { $stmt = $db->prepare($event_delete_query); } catch (\Exception $e) { $error->create(array('type' => 'sql_prepare_error', 'message' => $e->getMessage())); } $stmt->bindParam(':site_id', $site_id, database::PARAM_INT); try { $stmt->execute(); } catch (\Exception $e) { $error->create(array('type' => 'sql_execute_error', 'message' => $e->getMessage())); } } else { $events_to_delete = 0; } $log_array['event_severity'] = 'notice'; $log_array['event_number'] = E_USER_NOTICE; $log_array['event_description'] = 'Logs auto prune has finished and deleted ' . $events_to_delete . ' events.'; $log_array['event_file'] = __FILE__; $log_array['event_file_line'] = __LINE__; $log_array['event_type'] = 'prune'; $log_array['event_source'] = 'log'; $log_array['event_version'] = '1'; $log_array['log_backtrace'] = false; $log->add($log_array); } }
/** * Logs out the current user. */ public function logout() { $plugins =& singleton::get(__NAMESPACE__ . '\\plugins'); $plugins->run('auth_logout_start'); unset($this->current_user); session_destroy(); }
function delete($array = NULL) { global $db; $tables =& singleton::get(__NAMESPACE__ . '\\tables'); $error =& singleton::get(__NAMESPACE__ . '\\error'); $log =& singleton::get(__NAMESPACE__ . '\\log'); $site_id = SITE_ID; $query = "DELETE FROM {$tables->users_to_departments} WHERE site_id = :site_id"; if (isset($array['id'])) { $query .= " AND id = :id"; } if (isset($array['user_id'])) { $query .= " AND user_id = :user_id"; } if (isset($array['department_id'])) { $query .= " AND department_id = :department_id"; } try { $stmt = $db->prepare($query); } catch (\PDOException $e) { $error->create(array('type' => 'sql_prepare_error', 'message' => $e->getMessage())); } $stmt->bindParam(':site_id', $site_id, database::PARAM_INT); if (isset($array['id'])) { $stmt->bindParam(':id', $array['id'], database::PARAM_INT); } if (isset($array['user_id'])) { $stmt->bindParam(':user_id', $array['user_id'], database::PARAM_INT); } if (isset($array['department_id'])) { $stmt->bindParam(':department_id', $array['department_id'], database::PARAM_INT); } try { $stmt->execute(); } catch (\PDOException $e) { $error->create(array('type' => 'sql_execute_error', 'message' => $e->getMessage())); } }
function get($array = NULL) { global $db; $tables =& singleton::get(__NAMESPACE__ . '\\tables'); $error =& singleton::get(__NAMESPACE__ . '\\error'); $site_id = SITE_ID; $query = "SELECT mn.*, {$tables->users}.name, {$tables->users}.email FROM {$tables->message_notes} mn, {$tables->users} WHERE mn.site_id = :site_id"; if (isset($array['id'])) { $query .= " AND mn.id = :id"; } if (isset($array['user_id'])) { $query .= " AND mn.user_id = :user_id"; } if (isset($array['message_id'])) { $query .= " AND mn.message_id = :message_id"; } $query .= " AND {$tables->users}.id = mn.user_id"; $query .= " ORDER BY mn.id"; try { $stmt = $db->prepare($query); } catch (\PDOException $e) { $error->create(array('type' => 'sql_prepare_error', 'message' => $e->getMessage())); } $stmt->bindParam(':site_id', $site_id, database::PARAM_INT); if (isset($array['id'])) { $stmt->bindParam(':id', $array['id'], database::PARAM_INT); } if (isset($array['user_id'])) { $stmt->bindParam(':user_id', $array['user_id'], database::PARAM_INT); } if (isset($array['message_id'])) { $stmt->bindParam(':message_id', $array['message_id'], database::PARAM_INT); } try { $stmt->execute(); } catch (\PDOException $e) { $error->create(array('type' => 'sql_execute_error', 'message' => $e->getMessage())); } $items = $stmt->fetchAll(database::FETCH_ASSOC); return $items; }
/** * Deletes a config value from the database * * @param string $config_name The configuration item you want to delete * @return bool TRUE if deleted, FALSE if the value does not exists */ public function delete($config_name) { global $db; $error =& singleton::get(__NAMESPACE__ . '\\error'); $tables =& singleton::get(__NAMESPACE__ . '\\tables'); $site_id = SITE_ID; if (isset($this->config[$config_name])) { $stmt = $db->prepare("DELETE FROM {$tables->config} WHERE config_name = :name AND `site_id` = :site_id"); $stmt->bindParam(':name', $config_name); $stmt->bindParam(':site_id', $site_id, database::PARAM_INT); try { $stmt->execute(); } catch (Exception $e) { $error->create(array('type' => 'sql_execute_error', 'message' => $e->getMessage())); } unset($this->config[$config_name]); return true; } else { return false; } }