first commit
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Admin_Controller extends SAV_Controller {
|
||||
|
||||
const NONE_COUNT_RECORD = false;
|
||||
const TEMP_DIRECTORY_UPLOAD = 'application/cache/upload';
|
||||
const TEMP_DIRECTORY_DOWNLOAD = 'application/cache/download';
|
||||
|
||||
protected $read_replica;
|
||||
|
||||
var $template = array(
|
||||
'table_open' => "<table style='background-color:aliceblue' class='table table-striped table-hover table-bordered table-condensed'>",
|
||||
'thead_open' => '<thead class=\'bg-indigo\'>',
|
||||
'thead_close' => '</thead>',
|
||||
'heading_row_start' => '<tr>',
|
||||
'heading_row_end' => '</tr>',
|
||||
'heading_cell_start' => '<th>',
|
||||
'heading_cell_end' => '</th>',
|
||||
'tbody_open' => '<tbody>',
|
||||
'tbody_close' => '</tbody>',
|
||||
'row_start' => '<tr>',
|
||||
'row_end' => '</tr>',
|
||||
'cell_start' => '<td>',
|
||||
'cell_end' => '</td>',
|
||||
'row_alt_start' => '<tr>',
|
||||
'row_alt_end' => '</tr>',
|
||||
'cell_alt_start' => '<td>',
|
||||
'cell_alt_end' => '</td>',
|
||||
'table_close' => '</table>'
|
||||
);
|
||||
|
||||
var $template_small = array(
|
||||
'table_open' => "<table class='table table-striped table-hover table-bordered table-condensed' style='font-size:10px;'>",
|
||||
'thead_open' => '<thead class=\'bg-teal\'>',
|
||||
'thead_close' => '</thead>',
|
||||
'heading_row_start' => '<tr>',
|
||||
'heading_row_end' => '</tr>',
|
||||
'heading_cell_start' => '<th>',
|
||||
'heading_cell_end' => '</th>',
|
||||
'tbody_open' => '<tbody>',
|
||||
'tbody_close' => '</tbody>',
|
||||
'row_start' => '<tr>',
|
||||
'row_end' => '</tr>',
|
||||
'cell_start' => '<td>',
|
||||
'cell_end' => '</td>',
|
||||
'row_alt_start' => '<tr>',
|
||||
'row_alt_end' => '</tr>',
|
||||
'cell_alt_start' => '<td>',
|
||||
'cell_alt_end' => '</td>',
|
||||
'table_close' => '</table>'
|
||||
);
|
||||
|
||||
public $data = array();
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
|
||||
if (!isset($_SESSION['username']) or $_SESSION['username'] == '' or $_SESSION['firstname'] == '') {
|
||||
redirect('logout');
|
||||
}
|
||||
}
|
||||
|
||||
protected function renderCardPage($page_name, $data) {
|
||||
$this->load->view('admin/view_admin_header', $data);
|
||||
$this->load->view('cards/' . $page_name, $data);
|
||||
$this->load->view('admin/view_admin_footer', $data);
|
||||
}
|
||||
|
||||
protected function renderEmissionPage($page_name, $data){
|
||||
$this->load->view('admin/view_admin_header', $data);
|
||||
$this->load->view('emission/' . $page_name, $data);
|
||||
$this->load->view('admin/view_admin_footer', $data);
|
||||
|
||||
}
|
||||
|
||||
protected function returnAdminTable($tbq, $pgLink, $config = []) {
|
||||
$this->load->library('pagination');
|
||||
|
||||
$query = $this->read_replica->query($tbq['count_query']);
|
||||
$config['total_rows'] = $query->num_rows();
|
||||
$config['base_url'] = base_url() . $pgLink;
|
||||
$config['per_page'] = $config['per_page'] ?? 5;
|
||||
$config['reuse_query_string'] = $config['reuse_query_string'] ?? FALSE;
|
||||
$config['uri_segment'] = $config['uri_segment'] ?? 3;
|
||||
$config['num_links'] = 5;
|
||||
$config['full_tag_open'] = "<ul class='pagination'>";
|
||||
$config['full_tag_close'] = "</ul>";
|
||||
$config['num_tag_open'] = '<li>';
|
||||
$config['num_tag_close'] = '</li>';
|
||||
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
|
||||
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
|
||||
$config['next_tag_open'] = "<li>";
|
||||
$config['next_tagl_close'] = "</li>";
|
||||
$config['prev_tag_open'] = "<li>";
|
||||
$config['prev_tagl_close'] = "</li>";
|
||||
$config['first_tag_open'] = "<li>";
|
||||
$config['first_tagl_close'] = "</li>";
|
||||
$config['last_tag_open'] = "<li>";
|
||||
$config['last_tagl_close'] = "</li>";
|
||||
|
||||
$this->pagination->initialize($config);
|
||||
$page = ($this->uri->segment($config['uri_segment'])) ? $this->uri->segment($config['uri_segment']) : 0;
|
||||
$page = is_numeric($page) ? $page : 0;
|
||||
|
||||
$mysql = $tbq['query'] . " LIMIT " . $config["per_page"] . " OFFSET " . $page;
|
||||
|
||||
$this->load->library('table');
|
||||
$this->table->set_template($this->template);
|
||||
$query = $this->read_replica->query($mysql);
|
||||
|
||||
|
||||
$data['limited_data'] = $query->result_array();
|
||||
$data['output_table'] = $this->table->generate($query);
|
||||
$data['links'] = $this->pagination->create_links();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function makeGoogleAddress($rect) {
|
||||
$data['directionsStart'] = $rect['to_street'] . "," . $rect['to_city'] . "," . $rect['to_state'] . " " . $rect['to_zipcode'] . ", USA";
|
||||
$data['directionsEnd'] = $rect['from_street'] . "," . $rect['from_city'] . "," . $rect['from_state'] . " " . $rect['from_zipcode'] . ", USA";
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Bko_Controller extends SAV_Controller {
|
||||
|
||||
public $data = array();
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
if (!isset($_SESSION['username']) or $_SESSION['username'] == '') {
|
||||
//redirect('site');
|
||||
} else {
|
||||
// erase the session properly if here
|
||||
redirect('dash');
|
||||
}
|
||||
}
|
||||
|
||||
protected function buildUserSession($ret, $out) {
|
||||
|
||||
|
||||
|
||||
if ($ret == PHP_API_OK) {
|
||||
$_SESSION['session_id'] = $out["sessionid"];
|
||||
$_SESSION['sessionid'] = $out["sessionid"];
|
||||
$_SESSION['username'] = $out["username"]; // $this->input->post('username');
|
||||
$_SESSION['firstname'] = $out["firstname"]; // $ret->firstname;
|
||||
$_SESSION['lastname'] = $out["lastname"]; // $ret->lastname;
|
||||
$_SESSION['email'] = $out["email"]; // $ret->email;
|
||||
$_SESSION['backoffice_id'] = $out["username"]; // $ret->id;
|
||||
$_SESSION['pid'] = $out["pid"]; // $ret->id;
|
||||
$_SESSION['loc'] = $out["loc"];
|
||||
|
||||
}
|
||||
|
||||
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
|
||||
$_SESSION['loc'] = $_SERVER['HTTP_CLIENT_IP'];
|
||||
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||
$_SESSION['loc'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||
} else {
|
||||
$_SESSION['loc'] = $_SERVER['REMOTE_ADDR'];
|
||||
}
|
||||
}
|
||||
|
||||
protected function testLoginInput(&$username, &$password, &$error_message, &$valid_entry) {
|
||||
$valid_entry = true;
|
||||
$username = trim($this->input->post('username'));
|
||||
$password = trim($this->input->post('password'));
|
||||
if ($username == '' or $password == '') {
|
||||
$valid_entry = false;
|
||||
$error_message = 'Enter a Username/Password to continue';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,548 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
|
||||
* For licensing, see LICENSE.html or http://ckeditor.com/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* \brief CKEditor class that can be used to create editor
|
||||
* instances in PHP pages on server side.
|
||||
* @see http://ckeditor.com
|
||||
*
|
||||
* Sample usage:
|
||||
* @code
|
||||
* $CKEditor = new CKEditor();
|
||||
* $CKEditor->editor("editor1", "<p>Initial value.</p>");
|
||||
* @endcode
|
||||
*/
|
||||
class Ckeditor
|
||||
{
|
||||
/**
|
||||
* The version of %CKEditor.
|
||||
*/
|
||||
const version = '3.6.1';
|
||||
/**
|
||||
* A constant string unique for each release of %CKEditor.
|
||||
*/
|
||||
const timestamp = 'B5GJ5GG';
|
||||
|
||||
/**
|
||||
* URL to the %CKEditor installation directory (absolute or relative to document root).
|
||||
* If not set, CKEditor will try to guess it's path.
|
||||
*
|
||||
* Example usage:
|
||||
* @code
|
||||
* $CKEditor->basePath = '/ckeditor/';
|
||||
* @endcode
|
||||
*/
|
||||
public $basePath;
|
||||
/**
|
||||
* An array that holds the global %CKEditor configuration.
|
||||
* For the list of available options, see http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html
|
||||
*
|
||||
* Example usage:
|
||||
* @code
|
||||
* $CKEditor->config['height'] = 400;
|
||||
* // Use @@ at the beggining of a string to ouput it without surrounding quotes.
|
||||
* $CKEditor->config['width'] = '@@screen.width * 0.8';
|
||||
* @endcode
|
||||
*/
|
||||
public $config = array();
|
||||
/**
|
||||
* A boolean variable indicating whether CKEditor has been initialized.
|
||||
* Set it to true only if you have already included
|
||||
* <script> tag loading ckeditor.js in your website.
|
||||
*/
|
||||
public $initialized = false;
|
||||
/**
|
||||
* Boolean variable indicating whether created code should be printed out or returned by a function.
|
||||
*
|
||||
* Example 1: get the code creating %CKEditor instance and print it on a page with the "echo" function.
|
||||
* @code
|
||||
* $CKEditor = new CKEditor();
|
||||
* $CKEditor->returnOutput = true;
|
||||
* $code = $CKEditor->editor("editor1", "<p>Initial value.</p>");
|
||||
* echo "<p>Editor 1:</p>";
|
||||
* echo $code;
|
||||
* @endcode
|
||||
*/
|
||||
public $returnOutput = false;
|
||||
/**
|
||||
* An array with textarea attributes.
|
||||
*
|
||||
* When %CKEditor is created with the editor() method, a HTML <textarea> element is created,
|
||||
* it will be displayed to anyone with JavaScript disabled or with incompatible browser.
|
||||
*/
|
||||
public $textareaAttributes = array("rows" => 8, "cols" => 60);
|
||||
/**
|
||||
* A string indicating the creation date of %CKEditor.
|
||||
* Do not change it unless you want to force browsers to not use previously cached version of %CKEditor.
|
||||
*/
|
||||
public $timestamp = "B5GJ5GG";
|
||||
/**
|
||||
* An array that holds event listeners.
|
||||
*/
|
||||
private $events = array();
|
||||
/**
|
||||
* An array that holds global event listeners.
|
||||
*/
|
||||
private $globalEvents = array();
|
||||
|
||||
/**
|
||||
* Main Constructor.
|
||||
*
|
||||
* @param $basePath (string) URL to the %CKEditor installation directory (optional).
|
||||
*/
|
||||
function __construct($basePath = null)
|
||||
{
|
||||
if (!empty($basePath)) {
|
||||
$this->basePath = $basePath;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a %CKEditor instance.
|
||||
* In incompatible browsers %CKEditor will downgrade to plain HTML <textarea> element.
|
||||
*
|
||||
* @param $name (string) Name of the %CKEditor instance (this will be also the "name" attribute of textarea element).
|
||||
* @param $value (string) Initial value (optional).
|
||||
* @param $config (array) The specific configurations to apply to this editor instance (optional).
|
||||
* @param $events (array) Event listeners for this editor instance (optional).
|
||||
*
|
||||
* Example usage:
|
||||
* @code
|
||||
* $CKEditor = new CKEditor();
|
||||
* $CKEditor->editor("field1", "<p>Initial value.</p>");
|
||||
* @endcode
|
||||
*
|
||||
* Advanced example:
|
||||
* @code
|
||||
* $CKEditor = new CKEditor();
|
||||
* $config = array();
|
||||
* $config['toolbar'] = array(
|
||||
* array( 'Source', '-', 'Bold', 'Italic', 'Underline', 'Strike' ),
|
||||
* array( 'Image', 'Link', 'Unlink', 'Anchor' )
|
||||
* );
|
||||
* $events['instanceReady'] = 'function (ev) {
|
||||
* alert("Loaded: " + ev.editor.name);
|
||||
* }';
|
||||
* $CKEditor->editor("field1", "<p>Initial value.</p>", $config, $events);
|
||||
* @endcode
|
||||
*/
|
||||
public function editor($name, $value = "", $config = array(), $events = array())
|
||||
{
|
||||
$attr = "";
|
||||
foreach ($this->textareaAttributes as $key => $val) {
|
||||
$attr .= " " . $key . '="' . str_replace('"', '"', $val) . '"';
|
||||
}
|
||||
$out = "<textarea name=\"" . $name . "\"" . $attr . ">" . htmlspecialchars($value) . "</textarea>\n";
|
||||
if (!$this->initialized) {
|
||||
$out .= $this->init();
|
||||
}
|
||||
|
||||
$_config = $this->configSettings($config, $events);
|
||||
|
||||
$js = $this->returnGlobalEvents();
|
||||
if (!empty($_config))
|
||||
$js .= "CKEDITOR.replace('" . $name . "', " . $this->jsEncode($_config) . ");";
|
||||
else
|
||||
$js .= "CKEDITOR.replace('" . $name . "');";
|
||||
|
||||
$out .= $this->script($js);
|
||||
|
||||
if (!$this->returnOutput) {
|
||||
print $out;
|
||||
$out = "";
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces a <textarea> with a %CKEditor instance.
|
||||
*
|
||||
* @param $id (string) The id or name of textarea element.
|
||||
* @param $config (array) The specific configurations to apply to this editor instance (optional).
|
||||
* @param $events (array) Event listeners for this editor instance (optional).
|
||||
*
|
||||
* Example 1: adding %CKEditor to <textarea name="article"></textarea> element:
|
||||
* @code
|
||||
* $CKEditor = new CKEditor();
|
||||
* $CKEditor->replace("article");
|
||||
* @endcode
|
||||
*/
|
||||
public function replace($id, $config = array(), $events = array())
|
||||
{
|
||||
$out = "";
|
||||
if (!$this->initialized) {
|
||||
$out .= $this->init();
|
||||
}
|
||||
|
||||
$_config = $this->configSettings($config, $events);
|
||||
|
||||
$js = $this->returnGlobalEvents();
|
||||
if (!empty($_config)) {
|
||||
$js .= "CKEDITOR.replace('" . $id . "', " . $this->jsEncode($_config) . ");";
|
||||
} else {
|
||||
$js .= "CKEDITOR.replace('" . $id . "');";
|
||||
}
|
||||
$out .= $this->script($js);
|
||||
|
||||
if (!$this->returnOutput) {
|
||||
print $out;
|
||||
$out = "";
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace all <textarea> elements available in the document with editor instances.
|
||||
*
|
||||
* @param $className (string) If set, replace all textareas with class className in the page.
|
||||
*
|
||||
* Example 1: replace all <textarea> elements in the page.
|
||||
* @code
|
||||
* $CKEditor = new CKEditor();
|
||||
* $CKEditor->replaceAll();
|
||||
* @endcode
|
||||
*
|
||||
* Example 2: replace all <textarea class="myClassName"> elements in the page.
|
||||
* @code
|
||||
* $CKEditor = new CKEditor();
|
||||
* $CKEditor->replaceAll( 'myClassName' );
|
||||
* @endcode
|
||||
*/
|
||||
public function replaceAll($className = null)
|
||||
{
|
||||
$out = "";
|
||||
if (!$this->initialized) {
|
||||
$out .= $this->init();
|
||||
}
|
||||
|
||||
$_config = $this->configSettings();
|
||||
|
||||
$js = $this->returnGlobalEvents();
|
||||
if (empty($_config)) {
|
||||
if (empty($className)) {
|
||||
$js .= "CKEDITOR.replaceAll();";
|
||||
} else {
|
||||
$js .= "CKEDITOR.replaceAll('" . $className . "');";
|
||||
}
|
||||
} else {
|
||||
$classDetection = "";
|
||||
$js .= "CKEDITOR.replaceAll( function(textarea, config) {\n";
|
||||
if (!empty($className)) {
|
||||
$js .= " var classRegex = new RegExp('(?:^| )' + '" . $className . "' + '(?:$| )');\n";
|
||||
$js .= " if (!classRegex.test(textarea.className))\n";
|
||||
$js .= " return false;\n";
|
||||
}
|
||||
$js .= " CKEDITOR.tools.extend(config, " . $this->jsEncode($_config) . ", true);";
|
||||
$js .= "} );";
|
||||
}
|
||||
|
||||
$out .= $this->script($js);
|
||||
|
||||
if (!$this->returnOutput) {
|
||||
print $out;
|
||||
$out = "";
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds event listener.
|
||||
* Events are fired by %CKEditor in various situations.
|
||||
*
|
||||
* @param $event (string) Event name.
|
||||
* @param $javascriptCode (string) Javascript anonymous function or function name.
|
||||
*
|
||||
* Example usage:
|
||||
* @code
|
||||
* $CKEditor->addEventHandler('instanceReady', 'function (ev) {
|
||||
* alert("Loaded: " + ev.editor.name);
|
||||
* }');
|
||||
* @endcode
|
||||
*/
|
||||
public function addEventHandler($event, $javascriptCode)
|
||||
{
|
||||
if (!isset($this->events[$event])) {
|
||||
$this->events[$event] = array();
|
||||
}
|
||||
// Avoid duplicates.
|
||||
if (!in_array($javascriptCode, $this->events[$event])) {
|
||||
$this->events[$event][] = $javascriptCode;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear registered event handlers.
|
||||
* Note: this function will have no effect on already created editor instances.
|
||||
*
|
||||
* @param $event (string) Event name, if not set all event handlers will be removed (optional).
|
||||
*/
|
||||
public function clearEventHandlers($event = null)
|
||||
{
|
||||
if (!empty($event)) {
|
||||
$this->events[$event] = array();
|
||||
} else {
|
||||
$this->events = array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds global event listener.
|
||||
*
|
||||
* @param $event (string) Event name.
|
||||
* @param $javascriptCode (string) Javascript anonymous function or function name.
|
||||
*
|
||||
* Example usage:
|
||||
* @code
|
||||
* $CKEditor->addGlobalEventHandler('dialogDefinition', 'function (ev) {
|
||||
* alert("Loading dialog: " + ev.data.name);
|
||||
* }');
|
||||
* @endcode
|
||||
*/
|
||||
public function addGlobalEventHandler($event, $javascriptCode)
|
||||
{
|
||||
if (!isset($this->globalEvents[$event])) {
|
||||
$this->globalEvents[$event] = array();
|
||||
}
|
||||
// Avoid duplicates.
|
||||
if (!in_array($javascriptCode, $this->globalEvents[$event])) {
|
||||
$this->globalEvents[$event][] = $javascriptCode;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear registered global event handlers.
|
||||
* Note: this function will have no effect if the event handler has been already printed/returned.
|
||||
*
|
||||
* @param $event (string) Event name, if not set all event handlers will be removed (optional).
|
||||
*/
|
||||
public function clearGlobalEventHandlers($event = null)
|
||||
{
|
||||
if (!empty($event)) {
|
||||
$this->globalEvents[$event] = array();
|
||||
} else {
|
||||
$this->globalEvents = array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints javascript code.
|
||||
*
|
||||
* @param string $js
|
||||
*/
|
||||
private function script($js)
|
||||
{
|
||||
$out = "<script type=\"text/javascript\">";
|
||||
$out .= "//<![CDATA[\n";
|
||||
$out .= $js;
|
||||
$out .= "\n//]]>";
|
||||
$out .= "</script>\n";
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configuration array (global and instance specific settings are merged into one array).
|
||||
*
|
||||
* @param $config (array) The specific configurations to apply to editor instance.
|
||||
* @param $events (array) Event listeners for editor instance.
|
||||
*/
|
||||
private function configSettings($config = array(), $events = array())
|
||||
{
|
||||
$_config = $this->config;
|
||||
$_events = $this->events;
|
||||
|
||||
if (is_array($config) && !empty($config)) {
|
||||
$_config = array_merge($_config, $config);
|
||||
}
|
||||
|
||||
if (is_array($events) && !empty($events)) {
|
||||
foreach ($events as $eventName => $code) {
|
||||
if (!isset($_events[$eventName])) {
|
||||
$_events[$eventName] = array();
|
||||
}
|
||||
if (!in_array($code, $_events[$eventName])) {
|
||||
$_events[$eventName][] = $code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_events)) {
|
||||
foreach ($_events as $eventName => $handlers) {
|
||||
if (empty($handlers)) {
|
||||
continue;
|
||||
} else if (count($handlers) == 1) {
|
||||
$_config['on'][$eventName] = '@@' . $handlers[0];
|
||||
} else {
|
||||
$_config['on'][$eventName] = '@@function (ev){';
|
||||
foreach ($handlers as $handler => $code) {
|
||||
$_config['on'][$eventName] .= '(' . $code . ')(ev);';
|
||||
}
|
||||
$_config['on'][$eventName] .= '}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return global event handlers.
|
||||
*/
|
||||
private function returnGlobalEvents()
|
||||
{
|
||||
static $returnedEvents;
|
||||
$out = "";
|
||||
|
||||
if (!isset($returnedEvents)) {
|
||||
$returnedEvents = array();
|
||||
}
|
||||
|
||||
if (!empty($this->globalEvents)) {
|
||||
foreach ($this->globalEvents as $eventName => $handlers) {
|
||||
foreach ($handlers as $handler => $code) {
|
||||
if (!isset($returnedEvents[$eventName])) {
|
||||
$returnedEvents[$eventName] = array();
|
||||
}
|
||||
// Return only new events
|
||||
if (!in_array($code, $returnedEvents[$eventName])) {
|
||||
$out .= ($code ? "\n" : "") . "CKEDITOR.on('" . $eventName . "', $code);";
|
||||
$returnedEvents[$eventName][] = $code;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes CKEditor (executed only once).
|
||||
*/
|
||||
private function init()
|
||||
{
|
||||
static $initComplete;
|
||||
$out = "";
|
||||
|
||||
if (!empty($initComplete)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if ($this->initialized) {
|
||||
$initComplete = true;
|
||||
return "";
|
||||
}
|
||||
|
||||
$args = "";
|
||||
$ckeditorPath = $this->ckeditorPath();
|
||||
|
||||
if (!empty($this->timestamp) && $this->timestamp != "%" . "TIMESTAMP%") {
|
||||
$args = '?t=' . $this->timestamp;
|
||||
}
|
||||
|
||||
// Skip relative paths...
|
||||
if (strpos($ckeditorPath, '..') !== 0) {
|
||||
$out .= $this->script("window.CKEDITOR_BASEPATH='" . $ckeditorPath . "';");
|
||||
}
|
||||
|
||||
$out .= "<script type=\"text/javascript\" src=\"" . $ckeditorPath . 'ckeditor.js' . $args . "\"></script>\n";
|
||||
|
||||
$extraCode = "";
|
||||
if ($this->timestamp != self::timestamp) {
|
||||
$extraCode .= ($extraCode ? "\n" : "") . "CKEDITOR.timestamp = '" . $this->timestamp . "';";
|
||||
}
|
||||
if ($extraCode) {
|
||||
$out .= $this->script($extraCode);
|
||||
}
|
||||
|
||||
$initComplete = $this->initialized = true;
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return path to ckeditor.js.
|
||||
*/
|
||||
private function ckeditorPath()
|
||||
{
|
||||
if (!empty($this->basePath)) {
|
||||
return $this->basePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* The absolute pathname of the currently executing script.
|
||||
* Note: If a script is executed with the CLI, as a relative path, such as file.php or ../file.php,
|
||||
* $_SERVER['SCRIPT_FILENAME'] will contain the relative path specified by the user.
|
||||
*/
|
||||
if (isset($_SERVER['SCRIPT_FILENAME'])) {
|
||||
$realPath = dirname($_SERVER['SCRIPT_FILENAME']);
|
||||
} else {
|
||||
/**
|
||||
* realpath - Returns canonicalized absolute pathname
|
||||
*/
|
||||
$realPath = realpath('./');
|
||||
}
|
||||
|
||||
/**
|
||||
* The filename of the currently executing script, relative to the document root.
|
||||
* For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar
|
||||
* would be /test.php/foo.bar.
|
||||
*/
|
||||
$selfPath = dirname($_SERVER['PHP_SELF']);
|
||||
$file = str_replace("\\", "/", __FILE__);
|
||||
|
||||
if (!$selfPath || !$realPath || !$file) {
|
||||
return "/ckeditor/";
|
||||
}
|
||||
|
||||
$documentRoot = substr($realPath, 0, strlen($realPath) - strlen($selfPath));
|
||||
$fileUrl = substr($file, strlen($documentRoot));
|
||||
$ckeditorUrl = str_replace("ckeditor_php5.php", "", $fileUrl);
|
||||
|
||||
return $ckeditorUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* This little function provides a basic JSON support.
|
||||
*
|
||||
* @param mixed $val
|
||||
* @return string
|
||||
*/
|
||||
private function jsEncode($val)
|
||||
{
|
||||
if (is_null($val)) {
|
||||
return 'null';
|
||||
}
|
||||
if (is_bool($val)) {
|
||||
return $val ? 'true' : 'false';
|
||||
}
|
||||
if (is_int($val)) {
|
||||
return $val;
|
||||
}
|
||||
if (is_float($val)) {
|
||||
return str_replace(',', '.', $val);
|
||||
}
|
||||
if (is_array($val) || is_object($val)) {
|
||||
if (is_array($val) && (array_keys($val) === range(0, count($val) - 1))) {
|
||||
return '[' . implode(',', array_map(array($this, 'jsEncode'), $val)) . ']';
|
||||
}
|
||||
$temp = array();
|
||||
foreach ($val as $k => $v) {
|
||||
$temp[] = $this->jsEncode("{$k}") . ':' . $this->jsEncode($v);
|
||||
}
|
||||
return '{' . implode(',', $temp) . '}';
|
||||
}
|
||||
// String otherwise
|
||||
if (strpos($val, '@@') === 0)
|
||||
return substr($val, 2);
|
||||
if (strtoupper(substr($val, 0, 9)) == 'CKEDITOR.')
|
||||
return $val;
|
||||
|
||||
return '"' . str_replace(array("\\", "/", "\n", "\t", "\r", "\x08", "\x0c", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'), $val) . '"';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,352 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
# Imports the Google Cloud client library
|
||||
use Google\Cloud\Storage\StorageClient;
|
||||
|
||||
class GoogleStorage {
|
||||
|
||||
private $storage;
|
||||
private $projectId;
|
||||
private $authFile;
|
||||
public $prefix = 'adminsavvy';
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
public function Init($projectId, $authFile) {
|
||||
// Your Google Cloud Platform project ID
|
||||
$this->projectId = $projectId; // 'float-app-224118';
|
||||
// The file path to credentials JSON
|
||||
$this->authFile = $authFile; // './float-app-224118-52ef1783d2c5.json';
|
||||
// Instantiates a client
|
||||
$this->storage = new StorageClient([
|
||||
'projectId' => $projectId,
|
||||
'keyFile' => json_decode(file_get_contents($authFile), true)
|
||||
]);
|
||||
}
|
||||
/*
|
||||
* @type array $keyFile The contents of the service account credentials
|
||||
* .json file retrieved from the Google Developer's Console.
|
||||
* Ex: `json_decode(file_get_contents($path), true)`.
|
||||
* @type string $keyFilePath The full path to your service account
|
||||
* credentials .json file retrieved from the Google Developers
|
||||
* Console.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create a Cloud Storage Bucket.
|
||||
*
|
||||
* @param Google\Cloud\Storage\StorageClient $storage Google storage service client
|
||||
* @param string $bucketName name of the bucket to create.
|
||||
* @param string $options options for the new bucket.
|
||||
*
|
||||
* @return Google\Cloud\Storage\Bucket the newly created bucket.
|
||||
*/
|
||||
public function CreateBucket($bucketName) {
|
||||
// Creates the new bucket
|
||||
$bucket = $this->storage->createBucket($bucketName);
|
||||
//echo 'Bucket ' . $bucket->name() . ' created.';
|
||||
return $bucket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a Cloud Storage Bucket.
|
||||
*
|
||||
* @param Google\Cloud\Storage\StorageClient $storage Google storage service client
|
||||
* @param string $bucketName the name of the bucket to delete.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function DeleteBucket($bucketName)
|
||||
{
|
||||
$this->storage = new StorageClient();
|
||||
$bucket = $this->storage->bucket($bucketName);
|
||||
$bucket->delete();
|
||||
printf('Bucket deleted: %s' . PHP_EOL, $bucket->name());
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload a file.
|
||||
*
|
||||
* @param Google\Cloud\Storage\StorageClient $storage Google storage service client
|
||||
* @param string $bucketName the name of your Google Cloud bucket.
|
||||
* @param string $objectName the name of the object.
|
||||
* @param string $source the path to the file to upload.
|
||||
*
|
||||
* @return Psr\Http\Message\StreamInterface
|
||||
*/
|
||||
function UploadObject($bucketName, $objectName, $source)
|
||||
{
|
||||
$file = fopen($source, 'r');
|
||||
$bucket = $this->storage->bucket($bucketName);
|
||||
$object = $bucket->upload($file, [
|
||||
'name' => $objectName
|
||||
]);
|
||||
printf('Uploaded %s to gs://%s/%s' . PHP_EOL, basename($source), $bucketName, $objectName);
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Download an object from Cloud Storage and return it as a BLOB.
|
||||
*
|
||||
* @param Google\Cloud\Storage\StorageClient $storage Google storage service client
|
||||
* @param string $bucketName the name of your Google Cloud bucket.
|
||||
* @param string $objectName the name of your Google Cloud object.
|
||||
*
|
||||
* @return BLOB
|
||||
*/
|
||||
function DownloadObject($bucketName, $objectName)
|
||||
{
|
||||
$bucket = $this->storage->bucket($bucketName);
|
||||
$object = $bucket->object($objectName);
|
||||
$stream = $object->downloadAsStream();
|
||||
return $stream->getContents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an object.
|
||||
*
|
||||
* @param Google\Cloud\Storage\StorageClient $storage Google storage service client
|
||||
* @param string $bucketName the name of your Cloud Storage bucket.
|
||||
* @param string $objectName the name of your Cloud Storage object.
|
||||
* @param array $options
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function DeleteObject($bucketName, $objectName, $options = [])
|
||||
{
|
||||
$bucket = $this->storage->bucket($bucketName);
|
||||
$object = $bucket->object($objectName);
|
||||
$object->delete();
|
||||
$msg = sprintf('Deleted gs://%s/%s' . PHP_EOL, $bucketName, $objectName);
|
||||
echo $msg;
|
||||
return $msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an object publically accessible.
|
||||
*
|
||||
* @param Google\Cloud\Storage\StorageClient $storage Google storage service client
|
||||
* @param string $bucketName the name of your Cloud Storage bucket.
|
||||
* @param string $objectName the name of your Cloud Storage object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function MakePublic($bucketName, $objectName)
|
||||
{
|
||||
$bucket = $this->storage->bucket($bucketName);
|
||||
$object = $bucket->object($objectName);
|
||||
$object->update(['acl' => []], ['predefinedAcl' => 'PUBLICREAD']);
|
||||
printf('gs://%s/%s is now public' . PHP_EOL, $bucketName, $objectName);
|
||||
}
|
||||
|
||||
/**
|
||||
* List object metadata.
|
||||
*
|
||||
* @param Google\Cloud\Storage\StorageClient $storage Google storage service client
|
||||
* @param string $bucketName the name of your Cloud Storage bucket.
|
||||
* @param string $objectName the name of your Cloud Storage object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function ObjectMetadata($bucketName, $objectName)
|
||||
{
|
||||
$bucket = $this->storage->bucket($bucketName);
|
||||
$object = $bucket->object($objectName);
|
||||
$info = $object->info();
|
||||
printf('Blob: %s' . PHP_EOL, $info['name']);
|
||||
printf('Bucket: %s' . PHP_EOL, $info['bucket']);
|
||||
printf('Storage class: %s' . PHP_EOL, $info['storageClass']);
|
||||
printf('ID: %s' . PHP_EOL, $info['id']);
|
||||
printf('Size: %s' . PHP_EOL, $info['size']);
|
||||
printf('Updated: %s' . PHP_EOL, $info['updated']);
|
||||
printf('Generation: %s' . PHP_EOL, $info['generation']);
|
||||
printf('Metageneration: %s' . PHP_EOL, $info['metageneration']);
|
||||
printf('Etag: %s' . PHP_EOL, $info['etag']);
|
||||
printf('Crc32c: %s' . PHP_EOL, $info['crc32c']);
|
||||
printf('MD5 Hash: %s' . PHP_EOL, $info['md5Hash']);
|
||||
printf('Content-type: %s' . PHP_EOL, $info['contentType']);
|
||||
printf("Temporary hold: " . (isset($info['temporaryHold']) ? "enabled" : "disabled") . PHP_EOL);
|
||||
printf("Event-based hold: " . (isset($info['eventBasedHold']) ? "enabled" : "disabled") . PHP_EOL);
|
||||
if (isset($info['retentionExpirationTime'])) {
|
||||
printf("retentionExpirationTime: " . $info['retentionExpirationTime'] . PHP_EOL);
|
||||
}
|
||||
if (isset($info['metadata'])) {
|
||||
printf('Metadata: %s', print_r($info['metadata'], true));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List all Cloud Storage buckets for the current project.
|
||||
*
|
||||
* @param Google\Cloud\Storage\StorageClient $storage Google storage service client
|
||||
* @return void
|
||||
*/
|
||||
function ListBuckets()
|
||||
{
|
||||
$buckets = array();
|
||||
foreach ($this->storage->buckets() as $bucket) {
|
||||
//printf('Bucket: %s' . PHP_EOL, $bucket->name());
|
||||
$buckets[$bucket->name()] = $bucket;
|
||||
}
|
||||
return $buckets;
|
||||
}
|
||||
|
||||
/**
|
||||
* List Cloud Storage bucket objects.
|
||||
* https://cloud.google.com/storage/docs/listing-objects
|
||||
*
|
||||
* @param Google\Cloud\Storage\StorageClient $storage Google storage service client
|
||||
* @param string $bucketName the name of your Cloud Storage bucket.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function ListObjects($bucketName)
|
||||
{
|
||||
$objects = array();
|
||||
$bucket = $this->storage->bucket($bucketName);
|
||||
foreach ($bucket->objects() as $object) {
|
||||
//printf('Object: %s' . PHP_EOL, $object->name());
|
||||
$objects[$object->name()] = $object;
|
||||
}
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* List Cloud Storage bucket objects.
|
||||
* https://cloud.google.com/storage/docs/listing-objects
|
||||
*
|
||||
* @param Google\Cloud\Storage\StorageClient $storage Google storage service client
|
||||
* @param string $bucketName the name of your Cloud Storage bucket.
|
||||
* @param string $objectName the name of your Cloud Storage object.
|
||||
* @param string $responseType Response content-type for the object URL
|
||||
* @param integer $duration Number of seconds before the signature expires
|
||||
* @param string $method Optional HTTP verb for URL
|
||||
*
|
||||
* @return string Signed google storage URL
|
||||
*/
|
||||
function SignedUrl($bucketName, $objectName, $responseType, $duration = 60, $method = 'GET')
|
||||
{
|
||||
$bucket = $this->storage->bucket($bucketName);
|
||||
$object = $bucket->object($objectName);
|
||||
$url = $object->signedUrl(
|
||||
new \DateTime('+ ' . $duration . ' seconds'),
|
||||
array(
|
||||
'method' => $method,
|
||||
'responseType' => $responseType,
|
||||
'allowPost' => $method=='POST'
|
||||
));
|
||||
return $url;
|
||||
}
|
||||
/*
|
||||
'method' => 'GET',
|
||||
'cname' => self::DEFAULT_DOWNLOAD_URL,
|
||||
'contentMd5' => null,
|
||||
'contentType' => null,
|
||||
'headers' => [],
|
||||
'saveAsName' => null,
|
||||
'responseDisposition' => null,
|
||||
'responseType' => null,
|
||||
'keyFile' => null,
|
||||
'keyFilePath' => null,
|
||||
'allowPost' => false,
|
||||
'forceOpenssl' => false
|
||||
*/
|
||||
private function BaseEncode($num, $alphabet) {
|
||||
$base_count = strlen($alphabet);
|
||||
$encoded = '';
|
||||
while ($num >= $base_count) {
|
||||
$div = $num/$base_count;
|
||||
$mod = ($num-($base_count*intval($div)));
|
||||
if ($mod>=0 && $mod<$base_count) {
|
||||
$encoded = $alphabet[$mod] . $encoded;
|
||||
}
|
||||
$num = intval($div);
|
||||
}
|
||||
if ($num) $encoded = $alphabet[$num] . $encoded;
|
||||
return $encoded;
|
||||
}
|
||||
|
||||
private function BaseDecode($num, $alphabet) {
|
||||
$decoded = 0;
|
||||
$multi = 1;
|
||||
while (strlen($num) > 0) {
|
||||
$digit = $num[strlen($num)-1];
|
||||
$decoded += $multi * strpos($alphabet, $digit);
|
||||
$multi = $multi * strlen($alphabet);
|
||||
$num = substr($num, 0, -1);
|
||||
}
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
public function UniqueId() {
|
||||
// 123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ
|
||||
$alphabet = "pRFsNvKifkJtA5Umy9QSD8PTYcZH23dCeWg6aqVXwnr7jxuGMLhE4zBob1";
|
||||
return $this->BaseEncode(
|
||||
filter_var(microtime(),FILTER_SANITIZE_NUMBER_INT),
|
||||
$alphabet);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//*
|
||||
// run with GOOGLE_STORAGE_TEST=1 php -f GoogleStorage.php
|
||||
if (isset($_SERVER['GOOGLE_STORAGE_TEST']) && $_SERVER['GOOGLE_STORAGE_TEST']==1) {
|
||||
// Create bucket 'adminsavvy-card-images' and list buckets
|
||||
//TestGoogleStorage(1,1,0,0,0,0,0,0);
|
||||
// Upload 'singapore.jpg' file to 'adminsavvy-card-images' bucket and make the object public
|
||||
//TestGoogleStorage(0,0,1,1,0,0,0,0);
|
||||
// Download 'singapore.jpg' object from 'adminsavvy-card-images' bucket
|
||||
//TestGoogleStorage(0,0,0,0,0,0,1,0);
|
||||
// List buckets, List objects in 'adminsavvy-card-images' bucket, get 'singapore.jpg' object metadata, get signed URL
|
||||
TestGoogleStorage(0,1,0,0,1,1,0,1);
|
||||
}
|
||||
//*/
|
||||
/*
|
||||
* Run the test suite for above defined function
|
||||
*
|
||||
* @param integer $testCreateBucket 1 to run the create bucket test
|
||||
* @param integer $testListBuckets 1 to run the list buckets test
|
||||
* @param integer $testUploadObject 1 to run the upload object test
|
||||
* @param integer $testMakePublic 1 to run the make public test
|
||||
* @param integer $testListObjects 1 to run the list objects test
|
||||
* @param integer $testObjectMetadata 1 to run the object metadata test
|
||||
* @param integer $testDownloadObject 1 to run the download object test
|
||||
* @param integer $testSignedUrl 1 to run the signed URL test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function TestGoogleStorage(
|
||||
$testCreateBucket,
|
||||
$testListBuckets,
|
||||
$testUploadObject,
|
||||
$testMakePublic,
|
||||
$testListObjects,
|
||||
$testObjectMetadata,
|
||||
$testDownloadObject,
|
||||
$testSignedUrl) {
|
||||
// Your Google Cloud Platform project ID
|
||||
$projectId = 'float-app-224118';
|
||||
// The name for the new bucket
|
||||
$bucketName = 'adminsavvy-card-images';
|
||||
// The file path to upload
|
||||
$filePath = '/home/savvy/savvy/savvyoauth2/public/test/singapore.jpg';
|
||||
// The file path to credentials JSON
|
||||
$authFile = '/home/savvy/savvy/savvyoauth2/public/include/float-app-224118-52ef1783d2c5.json';
|
||||
|
||||
// Instantiates a client
|
||||
$storage = new GoogleStorage($projectId, $authFile);
|
||||
|
||||
if ($testCreateBucket) var_dump($storage->CreateBucket($bucketName));
|
||||
if ($testListBuckets) $storage->ListBuckets();
|
||||
if ($testUploadObject) var_dump($storage->UploadObject($bucketName, basename($filePath), $filePath));
|
||||
if ($testMakePublic) $storage->MakePublic($bucketName, basename($filePath));
|
||||
if ($testListObjects) $storage->ListObjects($bucketName);
|
||||
if ($testObjectMetadata) $storage->ObjectMetadata($bucketName, basename($filePath));
|
||||
if ($testDownloadObject) file_put_contents('test.jpg',$storage->DownloadObject($bucketName, basename($filePath)));
|
||||
if ($testSignedUrl) var_dump($storage->SignedUrl($bucketName, basename($filePath), mime_content_type($filePath), 864000));
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class MessageParser {
|
||||
|
||||
public function parse($id,$db) {
|
||||
global $savvyext;
|
||||
$data = array(
|
||||
'source_vendor' => 'Error',
|
||||
'date_value' => 'N/A',
|
||||
'date_score' => 'N/A',
|
||||
'date_end_value' => 'N/A',
|
||||
'date_end_score' => 'N/A',
|
||||
'location_start_value' => 'N/A',
|
||||
'location_start_score' => 'N/A',
|
||||
'location_end_value' => 'N/A',
|
||||
'location_end_score' => 'N/A',
|
||||
'distance_value' => 'N/A',
|
||||
'distance_score' => 'N/A',
|
||||
'duration_value' => 'N/A',
|
||||
'duration_score' => 'N/A',
|
||||
'cost_value' => 'N/A',
|
||||
'cost_score' => 'N/A',
|
||||
);
|
||||
// check the cache
|
||||
$q = "SELECT a.*, b.address AS location_start, b.latitude AS location_start_lat, b.longitude AS location_start_lng, b.timezone AS location_start_tz, b.geocoding_date AS location_geocoding_date, c.address AS location_end, c.latitude AS location_end_lat, c.longitude AS location_end_lng
|
||||
FROM parsedemail_item a
|
||||
LEFT JOIN address b ON b.id=a.location_start_id
|
||||
LEFT JOIN address c ON c.id=a.location_end_id
|
||||
WHERE a.trackedemail_item_id='${id}'";
|
||||
$r = $db->query($q);
|
||||
$f = $r->row_array();
|
||||
if ($f!=NULL) {
|
||||
$data['source_vendor'] = $f["transport_provider_id"];
|
||||
$data['date_value'] = $f["travel_date"];
|
||||
$data['date_end_value'] = $f["travel_date_end"];
|
||||
$data['location_start_value'] = $f["location_start"];
|
||||
$data['location_end_value'] = $f["location_end"];
|
||||
$data['distance_value'] = $f["distance"]==0?'N/A':$f["distance"];
|
||||
$data['duration_value'] = $f["duration"]==0?'N/A':$f["duration"];
|
||||
$data['cost_value'] = $f["cost"];
|
||||
return $data;
|
||||
}
|
||||
$url = $savvyext->cfgReadChar('system.oauth2_url')."parse/${id}";
|
||||
error_log($url);
|
||||
// hit the service
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Server-Token '.$savvyext->cfgReadChar('system.oauth2_token')));
|
||||
if( ! $result = curl_exec($ch)) {
|
||||
// Error
|
||||
} else {
|
||||
$raw_data = json_decode($result,true);
|
||||
if (is_array($raw_data) && !isset($raw_data['error']) && isset($raw_data['code']) &&
|
||||
$raw_data['code']=='0' && is_array($raw_data['data'])) {
|
||||
$data = $raw_data['data'];
|
||||
}
|
||||
}
|
||||
curl_close($ch);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
vi:ts=2
|
||||
*/
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class SAV_Form_validation extends CI_Form_validation
|
||||
{
|
||||
|
||||
protected $CI;
|
||||
|
||||
public function __construct($rules = array())
|
||||
{
|
||||
parent::__construct($rules);
|
||||
$this->CI = &get_instance();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* is_unique_multiple
|
||||
* check multiple unique field at time
|
||||
* handy when checking if two or more column of some set of value
|
||||
* e.g if firstname="something" and username="something"
|
||||
* usage:
|
||||
*is_unique_multiple[
|
||||
* table_name,
|
||||
* column_name1.column_name2.column_name3,
|
||||
* post_filed_name1.post_field_name2.post_field_name3
|
||||
*]
|
||||
*real example $this->form_validation->set_rules('fee_name', 'fee_name', "required|is_unique_multiple[arasoft_fee, fee_name.fee_term.fee_users, fee_name.term.fee_users ]");
|
||||
**/
|
||||
public function is_unique_multiple($str, $data)
|
||||
{
|
||||
$data = explode(",", $data);
|
||||
if (count($data) < 2)
|
||||
return TRUE;
|
||||
|
||||
$table = @$data[0];
|
||||
$str = @$data[1];
|
||||
$str = explode(".", $str);
|
||||
$field = @$data[2];
|
||||
|
||||
$field = empty($field) ? $str : explode(".", $field);
|
||||
if (count($str) != count($field)) {
|
||||
return TRUE;
|
||||
}
|
||||
$where = [];
|
||||
|
||||
foreach ($str as $key => $value) {
|
||||
# code...
|
||||
$q = $this->CI->input->post($field[$key]);
|
||||
$where[$value] = $q;
|
||||
}
|
||||
|
||||
$check = $this->CI->db->get_where($table, $where, 1);
|
||||
|
||||
if ($check->num_rows() > 0) {
|
||||
|
||||
$this->set_message('is_unique_multiple', 'This data exist already');
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
function exist($str, $data)
|
||||
{
|
||||
$data = explode(",", $data);
|
||||
if (count($data) < 2)
|
||||
return TRUE;
|
||||
|
||||
$table = @$data[0];
|
||||
$str = @$data[1];
|
||||
$str = explode(".", $str);
|
||||
$field = @$data[2];
|
||||
|
||||
$field = empty($field) ? $str : explode(".", $field);
|
||||
if (count($str) != count($field)) {
|
||||
return TRUE;
|
||||
}
|
||||
$where = [];
|
||||
|
||||
foreach ($str as $key => $value) {
|
||||
# code...
|
||||
$q = ! is_null($this->CI->input->post($field[$key]))
|
||||
? $this->CI->input->post($field[$key])
|
||||
: $this->CI->input->get($field[$key]);
|
||||
$where[$value] = $q;
|
||||
}
|
||||
|
||||
$check = $this->CI->db->get_where($table, $where, 1);
|
||||
|
||||
if ($check->num_rows() === 0) {
|
||||
|
||||
$this->set_message('exist', 'This data does not exists');
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
class Template {
|
||||
//ci instance
|
||||
private $CI;
|
||||
//template Data
|
||||
var $template_data = array();
|
||||
var $sideMenu = 'side_menu';
|
||||
var $header = 'header';
|
||||
var $footer = 'footer';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->CI =& get_instance();
|
||||
}
|
||||
|
||||
function set($content_area, $value)
|
||||
{
|
||||
$this->template_data[$content_area] = $value;
|
||||
}
|
||||
|
||||
function load($view = '' , $view_data = array(), $return = FALSE)
|
||||
{
|
||||
$siteMenuData['selectedTab'] = $view_data['selectedTab'];
|
||||
$this->set('header', $this->CI->load->view($this->header, null, TRUE));
|
||||
$this->set('footer', $this->CI->load->view($this->footer, null, TRUE));
|
||||
$this->set('side_menu', $this->CI->load->view($this->sideMenu, $siteMenuData, TRUE));
|
||||
$this->set('contents' , $this->CI->load->view($view, $view_data, TRUE));
|
||||
$this->CI->load->view('layouts/default_layout', $this->template_data);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class UploadHelper {
|
||||
|
||||
function deleteCardimageFile($data, $controller,$delete_table='',$delete_name='') {
|
||||
global $savvyext;
|
||||
$id = $data["id"];
|
||||
$q = "SELECT a.catid,a.uniqueid,a.name,a.format,b.name as catname FROM card_images a, card_image_category b WHERE a.id='${id}' AND b.id=a.catid";
|
||||
$r = $controller->db->query($q);
|
||||
$f = $r->row_array();
|
||||
if ($f==NULL || !is_array($f) || !isset($f["catname"])) {
|
||||
$data["message"] = 'Failed to load image data!';
|
||||
return $data;
|
||||
}
|
||||
$bucket_name = $f["catname"];
|
||||
$uniqueId = $f["uniqueid"];
|
||||
$controller->load->library('googlestorage');
|
||||
$controller->googlestorage->Init(
|
||||
$savvyext->cfgReadChar('google.storage_project_id'),
|
||||
$savvyext->cfgReadChar('google.storage_auth_file')
|
||||
);
|
||||
$storage = $controller->googlestorage;
|
||||
// Get bucket
|
||||
$buckets = $storage->ListBuckets();
|
||||
if (array_key_exists($bucket_name, $buckets)) {
|
||||
$bucket = $buckets[$bucket_name];
|
||||
}
|
||||
if ($bucket==NULL || !is_object($bucket)) {
|
||||
$data['message'] = 'Cannot get storage bucket!';
|
||||
return $data;
|
||||
}
|
||||
$objectName = $uniqueId.".".$f['format'];
|
||||
ob_start();
|
||||
$storage->DeleteObject($bucket_name, $objectName);
|
||||
$data["message"] = ob_get_clean();
|
||||
if (preg_match('/^Deleted gs:\/\/(.*)\/(.*)\.(.*)$/', $data["message"], $arr)==1 &&
|
||||
count($arr)>3 && $arr[1]==$bucket_name && $arr[2]==$uniqueId) {
|
||||
if ($delete_table!='' && $delete_name!='') {
|
||||
$q = "UPDATE ${delete_table} SET ${delete_name}=NULL WHERE ${delete_name}='${id}'";
|
||||
$controller->db->query($q);
|
||||
}
|
||||
$q = "DELETE FROM card_images WHERE id='${id}'";
|
||||
$controller->db->query($q);
|
||||
$data["deleted"] = $id;
|
||||
$data["message"] = "Image deleted!";
|
||||
} else {
|
||||
$data["deleted"] = 0;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function cardimagesPost($data,$controller,$uniqueId="") {
|
||||
global $savvyext;
|
||||
$bucket_name = '';
|
||||
$catid = (int)$controller->input->post('catid');
|
||||
if ($catid<1) { $data['message'] = 'Please select category'; return $data; }
|
||||
$q = "SELECT name FROM card_image_category WHERE id='${catid}'";
|
||||
$r = $controller->db->query($q);
|
||||
foreach ($r->result() as $row) {
|
||||
$bucket_name = $row->name;
|
||||
break;
|
||||
}
|
||||
if ($bucket_name=='') {
|
||||
$data['message'] = 'Invalid category';
|
||||
return $data;
|
||||
}
|
||||
// Process file
|
||||
$imgData = self::processFile('cardimg', array('jpg'=>1,'jpeg'=>1,'png'=>1,'gif'=>1));
|
||||
if ($imgData==NULL || !is_array($imgData)) {
|
||||
$data['message'] = 'Failed to process uploaded image! ('.$imgData.')';
|
||||
return $data;
|
||||
}
|
||||
$controller->load->library('googlestorage');
|
||||
$controller->googlestorage->Init(
|
||||
$savvyext->cfgReadChar('google.storage_project_id'),
|
||||
$savvyext->cfgReadChar('google.storage_auth_file')
|
||||
);
|
||||
$storage = $controller->googlestorage;
|
||||
// Get bucket
|
||||
$buckets = $storage->ListBuckets();
|
||||
if (array_key_exists($bucket_name, $buckets)) {
|
||||
$bucket = $buckets[$bucket_name];
|
||||
} else {
|
||||
// Create bucket
|
||||
$bucket = $storage->CreateBucket($bucket_name);
|
||||
}
|
||||
if ($bucket==NULL || !is_object($bucket)) {
|
||||
$data['message'] = 'Cannot get or create bucket!';
|
||||
return $data;
|
||||
}
|
||||
if ($uniqueId=="") {
|
||||
$uniqueId = $storage->UniqueId();
|
||||
}
|
||||
$data['format'] = $imgData['format'];
|
||||
$objectName = $uniqueId.".".$imgData['format'];
|
||||
$source = $imgData['tmp_name'];
|
||||
$object = $storage->UploadObject($bucket_name, $objectName, $source);
|
||||
if ($object==NULL || !is_object($object)) {
|
||||
$data['message'] = 'Failed to upload image!';
|
||||
} else {
|
||||
$data['message'] = 'Image uploaded!';
|
||||
// Save image data
|
||||
$q = "INSERT INTO card_images (catid, uniqueid, name, file_size, format, dimensions) VALUES(";
|
||||
$q.= "'${catid}','${uniqueId}','".$imgData['name']."','".$imgData['file_size']."','".$imgData['format']."','".$imgData['dimensions']."') RETURNING id";
|
||||
$r = $controller->db->query($q);
|
||||
$f = $r->row_array();
|
||||
if ($f!=NULL && is_array($f) && $f["id"]>0) {
|
||||
$data["card_image_id"] = $f["id"];
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function processFile($var, $formats) {
|
||||
if (!isset($_FILES[$var])) return 'The file was not uploaded!';
|
||||
if (is_array($_FILES[$var]['error'])) {
|
||||
foreach ($_FILES[$var]['error'] as $key => $error) {
|
||||
if ($error != UPLOAD_ERR_OK) {
|
||||
return $error;
|
||||
}
|
||||
}
|
||||
} else if (isset($_FILES[$var]['error']) && $_FILES[$var]['error'] != UPLOAD_ERR_OK) {
|
||||
return $_FILES[$var]['error'];
|
||||
}
|
||||
$error = $_FILES[$var]['error'];
|
||||
$name = trim($_FILES[$var]['name']);
|
||||
$file_size = $_FILES[$var]['size'];
|
||||
$tmp_name = $_FILES[$var]['tmp_name'];
|
||||
$format = strtolower(pathinfo($_FILES[$var]['name'], PATHINFO_EXTENSION));
|
||||
if (!isset($formats[$format]) || $formats[$format]!=1) {
|
||||
return 'Invalid file format: '.$format;
|
||||
}
|
||||
list($width, $height, $type, $attr) = getimagesize($tmp_name);
|
||||
$dimensions = $width . 'x' . $height;
|
||||
$result = array(
|
||||
'tmp_name' => $tmp_name,
|
||||
'name' => $name,
|
||||
'file_size' => $file_size,
|
||||
'format' => $format,
|
||||
'dimensions' => $dimensions
|
||||
);
|
||||
return $result;
|
||||
//return 'Not implemented!';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user