function time_since($client_id, $time, $now = FALSE, $date_format = 'M d, Y @ h:ia')
{
    if ($now == FALSE) {
        $now = time();
    }
    if (!is_numeric($time)) {
        $time = strtotime($time);
    }
    // calculate $since
    $since = $now - $time;
    // greater than a day?
    if ($since > 60 * 60 * 24) {
        // it's more than a day ago, let's just return the data
        $return = 'on ' . local_time($client_id, $time);
    } else {
        $chunks = array(array(60 * 60, 'hour'), array(60, 'minute'), array(1, 'second'));
        for ($i = 0, $j = count($chunks); $i < $j; $i++) {
            $seconds = $chunks[$i][0];
            $name = $chunks[$i][1];
            if (($count = floor($since / $seconds)) != 0) {
                break;
            }
        }
        $return = $count == 1 ? '1 ' . $name : "{$count} {$name}s";
        $return .= ' ago';
    }
    return $return;
}
示例#2
0
 public function getTable($pkey = '')
 {
     _has_user_access_permission(TRUE, array('admin', 'management_company', 'user_company'));
     $params = ($params = unserialize_object($pkey)) && is_array($params) ? $params : array();
     $company_id = $this->current_user->group_id == 1 ? isset($params[SYS_COMPANY_ID]) && gtzero_integer($params[SYS_COMPANY_ID]) ? to_int($params[SYS_COMPANY_ID]) : 0 : $this->current_user->company_id;
     $params = array('iDisplayStart' => $this->input->post('iDisplayStart', true), 'iDisplayLength' => $this->input->post('iDisplayLength', true), 'iSortCol_0' => $this->input->post('iSortCol_0', true), 'iSortingCols' => $this->input->post('iSortingCols', true), 'sSearch' => $this->input->post('sSearch', true), 'sEcho' => $this->input->post('sEcho', true), 'company_id' => $this->current_user->group_id == 1 ? $this->_post_args('company_id', ARGS_TYPE_INT, $company_id) : $this->current_user->company_id, 'name' => $this->_post_args('name', ARGS_TYPE_STRING), 'postcode' => $this->_post_args('postcode', ARGS_TYPE_STRING), 'contact_name' => $this->_post_args('contact_name', ARGS_TYPE_STRING));
     $qrows = $this->client_m->ajax_gets($params);
     foreach ($qrows['aaData'] as &$qrow) {
         $actions = array();
         if (in_array($this->current_user->group_id, array(GROUP_ADMIN, GROUP_MANAGEMENT_COMPANY))) {
             $actions['view'] = array('href' => site_url('clients/show/' . serialize_object(array(SYS_CLIENT_ID => $qrow->client_id))), 'title' => 'Client Detail<small>' . $qrow->full_name . '</small>', 'text' => 'Client Detail', 'params' => 'data-ajax="wdpajax" data-options=\'{"form_method" : "GET", "data_type" : "HTML", "role" : "modal", "created_new" : true, "title" : "Client Detail <small>' . $qrow->full_name . '</small>", "modal" : {"buttons" : false, "size" : "modal-lg", "footer" : false, "wizard" : true}, "params" : "echo"}\'', 'class' => array());
         }
         if (in_array($this->current_user->group_id, array(GROUP_ADMIN, GROUP_MANAGEMENT_COMPANY))) {
             $actions['edit'] = array('href' => site_url('clients/edit/' . serialize_object(array(SYS_CLIENT_ID => $qrow->client_id))), 'title' => 'Client Detail<small>' . $qrow->full_name . '</small>', 'text' => 'Edit Client', 'params' => 'data-ajax="wdpajax" data-options=\'{"form_method" : "GET", "data_type" : "HTML", "role" : "modal", "created_new" : true, "title" : "Client Detail", "modal" : {"buttons" : false, "footer" : false, "size" : "modal-lg", "wizard" : true, "override" : true, "modal_success_callback" : "gl.client.listing.load_grid(g);"}, "params" : "echo", "grid" : {"_init" : true, "gType" : "default"}}\'', 'class' => array());
         }
         if (in_array($this->current_user->group_id, array(GROUP_ADMIN, GROUP_MANAGEMENT_COMPANY))) {
             $actions['delete'] = array('href' => site_url('clients/delete/' . serialize_object(array(SYS_CLIENT_ID => $qrow->client_id))), 'title' => 'Client <small>' . $qrow->full_name . '</small>', 'text' => 'Delete Client', 'params' => 'data-ajax="wdpajax" data-options=\'{"form_method" : "GET", "data_type" : "HTML", "role" : "modal", "created_new" : true, "title" : "Delete Client <small>' . $qrow->full_name . '</small>", "modal" : {"buttons" : true, "override" : true, "modal_success_callback" : "gl.client.listing.load_grid(g);"}, "params" : "echo", "grid" : {"_init" : true, "gType" : "default"}}\'', 'class' => array());
         }
         /*if( in_array($this->current_user->group_id, array(GROUP_ADMIN, GROUP_MANAGEMENT_COMPANY)) ) {
         			$actions['notes'] = array(
         						'href' 		=> site_url('notes/index/'.serialize_object(array( SYS_REF_ID => $qrow->client_id, SYS_NOTE_TYPE_ID => NOTE_TYPE_CLIENT) )),
         						'title'		=> 'Notes <small>(Client: '.$qrow->full_name.')</small>',
         						'text'		=> 'Notes',
         						'params'	=> 'data-ajax="wdpajax" data-options=\'{"form_method" : "GET", "data_type" : "HTML", "role" : "modal", "created_new" : true, "title" : "Notes <small>(Client: '.$qrow->full_name.')</small>", "modal" : {"buttons" : false, "footer" : false, "size" : "modal-lg", "wizard" : true, "override" : true, "nopadd" : false, "modal_before_close_callback" : "gl.note.listing.close_grid(g);", "callback" : "gl.note.listing.load_grid(g);"}, "params" : "echo", "grid" : {"_init" : true, "gType" : "next"}}\'',
         						'class'		=> array()
         					);
         		
         		}
         		
         		if( in_array($this->current_user->group_id, array(GROUP_ADMIN, GROUP_MANAGEMENT_COMPANY)) ) {
         			$actions['new_note'] = array(
         						'href' 		=> site_url('notes/create/'.serialize_object(array( SYS_REF_ID => $qrow->client_id, SYS_NOTE_TYPE_ID => NOTE_TYPE_CLIENT))),
         						'title'		=> 'New Note <small>(Client: '.$qrow->full_name.')</small>',
         						'text'		=> 'New Note',
         						'params'	=> 'data-ajax="wdpajax" data-options=\'{"form_method" : "POST", "data_type" : "HTML", "role" : "modal", "created_new" : true, "title" : "Note Detail <small>(Client: '.$qrow->full_name.')</small>", "modal" : {"buttons" : true}, "params" : "echo"}\'',
         						'class'		=> array()
         					);
         		
         		}*/
         if (in_array($this->current_user->group_id, array(GROUP_ADMIN, GROUP_MANAGEMENT_COMPANY))) {
             $actions['contacts'] = array('href' => site_url('contacts/index/' . serialize_object(array(SYS_REF_ID => $qrow->client_id, SYS_CONTACT_TYPE_ID => CONTACT_TYPE_CLIENT))), 'title' => 'Contacts <small>(Client: ' . $qrow->full_name . ')</small>', 'text' => 'Contacts', 'params' => 'data-ajax="wdpajax" data-options=\'{"form_method" : "GET", "data_type" : "HTML", "role" : "modal", "created_new" : true, "title" : "Contacts <small>(Client: ' . $qrow->full_name . ')</small>", "modal" : {"buttons" : false, "footer" : false, "size" : "modal-lg", "wizard" : true, "override" : true, "nopadd" : false, "modal_before_close_callback" : "gl.contact.listing.close_grid(g);", "callback" : "gl.contact.listing.load_grid(g);"}, "params" : "echo", "grid" : {"_init" : true, "gType" : "next"}}\'', 'class' => array());
         }
         if (in_array($this->current_user->group_id, array(GROUP_ADMIN, GROUP_MANAGEMENT_COMPANY))) {
             $actions['new_contact'] = array('href' => site_url('contacts/create/' . serialize_object(array(SYS_REF_ID => $qrow->client_id, SYS_CONTACT_TYPE_ID => CONTACT_TYPE_CLIENT))), 'title' => 'Contact Detail <small>(Client: ' . $qrow->full_name . ')</small>', 'text' => 'New Contact', 'params' => 'data-ajax="wdpajax" data-options=\'{"form_method" : "POST", "data_type" : "HTML", "role" : "modal", "created_new" : true, "title" : "Contact Detail <small>(Client: ' . $qrow->full_name . ')</small>", "modal" : {"buttons" : true}, "params" : "echo"}\'', 'class' => array());
         }
         $qrow = array($qrow->full_name, $qrow->company_name, $qrow->address, $qrow->phone, $qrow->postcode, $qrow->contact_email, $qrow->created_by_name, local_time($qrow->created_on, 'M d, Y @ h:ia'), theme_button_dropdown($actions));
         if (_check_company_user_access()) {
             unset($qrow[1]);
             $qrow = array_values($qrow);
         }
     }
     echo json_encode($qrows);
 }
示例#3
0
 public function getTable($pkey = '')
 {
     _has_user_access_permission(TRUE, array('admin', 'location_manager', 'user_company'));
     $params = ($params = unserialize_object($pkey)) && is_array($params) ? $params : array();
     $type_id = isset($params[SYS_CONTACT_TYPE_ID]) && gtzero_integer($params[SYS_CONTACT_TYPE_ID]) ? to_int($params[SYS_CONTACT_TYPE_ID]) : 0;
     $ref_id = isset($params[SYS_REF_ID]) && gtzero_integer($params[SYS_REF_ID]) ? to_int($params[SYS_REF_ID]) : 0;
     $params = array('iDisplayStart' => $this->input->post('iDisplayStart', true), 'iDisplayLength' => $this->input->post('iDisplayLength', true), 'iSortCol_0' => $this->input->post('iSortCol_0', true), 'iSortingCols' => $this->input->post('iSortingCols', true), 'sSearch' => $this->input->post('sSearch', true), 'sEcho' => $this->input->post('sEcho', true), 'type_id' => $type_id, 'ref_id' => $ref_id);
     $qrows = $this->contact_m->ajax_gets($params);
     foreach ($qrows['aaData'] as &$qrow) {
         $qrow = array($qrow->full_name, $qrow->email, $qrow->address, $qrow->phone, $qrow->mobile, to_int($qrow->is_default) == 1 ? 'Yes' : 'No', $qrow->created_by_name, local_time($qrow->created_on, 'M d, Y'), theme_button_groups(array('edit' => array('href' => site_url('contacts/edit/' . serialize_object(array(SYS_CONTACT_ID => $qrow->contact_id, SYS_REF_ID => $qrow->ref_id, SYS_CONTACT_TYPE_ID => $qrow->contact_type_id))), 'title' => 'Contact Detail <small>' . $qrow->full_name . '</small>', 'text' => 'Edit Contact', 'params' => 'data-ajax="wdpajax" data-options=\'{"form_method" : "GET", "data_type" : "HTML", "role" : "modal", "created_new" : true, "title" : "Contact Detail (<small>' . $qrow->full_name . '</small>)", "modal" : {"buttons" : true, "override" : true, "modal_success_callback" : "gl.contact.listing.load_grid(g);"}, "params" : "echo", "grid" : {"_init" : true, "gType" : "default"}}\'', 'class' => array()), 'delete' => array('href' => site_url('contacts/delete/' . serialize_object(array(SYS_CONTACT_ID => $qrow->contact_id, SYS_REF_ID => $qrow->ref_id, SYS_CONTACT_TYPE_ID => $qrow->contact_type_id))), 'title' => 'Delete Contact <small>' . $qrow->full_name . '</small>', 'text' => 'Delete Contact', 'params' => 'data-ajax="wdpajax" data-options=\'{"form_method" : "GET", "data_type" : "HTML", "role" : "modal", "created_new" : true, "title" : "Contact (<small>' . $qrow->full_name . '</small>)", "modal" : {"buttons" : true, "override" : true, "modal_success_callback" : "gl.contact.listing.load_grid(g);"}, "params" : "echo", "grid" : {"_init" : true, "gType" : "default"}}\'', 'class' => array()))));
     }
     echo json_encode($qrows);
 }
示例#4
0
 public function getTable($pkey = '')
 {
     _has_user_access_permission(TRUE, array('admin', 'location_manager', 'location_user'));
     $params = ($params = unserialize_object($pkey)) && is_array($params) ? $params : array();
     $note_type_id = isset($params[SYS_NOTE_TYPE_ID]) && gtzero_integer($params[SYS_NOTE_TYPE_ID]) ? (int) $params[SYS_NOTE_TYPE_ID] : 0;
     $ref_id = isset($params[SYS_REF_ID]) && gtzero_integer($params[SYS_REF_ID]) ? (int) $params[SYS_REF_ID] : 0;
     $params = array('iDisplayStart' => $this->input->post('iDisplayStart', true), 'iDisplayLength' => $this->input->post('iDisplayLength', true), 'iSortCol_0' => $this->input->post('iSortCol_0', true), 'iSortingCols' => $this->input->post('iSortingCols', true), 'sSearch' => $this->input->post('sSearch', true), 'sEcho' => $this->input->post('sEcho', true), 'note_type_id' => $note_type_id, 'ref_id' => $ref_id);
     $qrows = $this->notes_m->ajax_gets($params);
     foreach ($qrows['aaData'] as &$qrow) {
         $qrow = array($qrow['note_description'], $qrow['created_by_name'], local_time($qrow['created_on'], 'M d, Y'), theme_button_groups(array('view' => array('href' => site_url('notes/show/' . serialize_object(array(SYS_NOTE_ID => $qrow['ID']))), 'title' => 'Note Detail', 'text' => 'View Note', 'params' => 'data-ajax="wdpajax" data-options=\'{"form_method" : "GET", "data_type" : "HTML", "role" : "modal", "created_new" : true, "title" : "Note Detail", "modal" : {"buttons" : false, "footer" : false}, "params" : "echo"}\'', 'class' => array()))));
     }
     echo json_encode($qrows);
 }
示例#5
0
 public function getTable($pkey = '')
 {
     _has_user_access_permission(TRUE, array('admin', 'management_company'));
     $params = ($params = unserialize_object($pkey)) && is_array($params) ? $params : array();
     $company_id = $this->current_user->group_id == 1 ? array_key_exists(SYS_COMPANY_ID, $params) && gtzero_integer($params[SYS_COMPANY_ID]) ? to_int($params[SYS_COMPANY_ID]) : 0 : $this->current_user->company_id;
     $input = array('iDisplayStart' => $this->_post_args('iDisplayStart', ARGS_TYPE_INT), 'iDisplayLength' => $this->_post_args('iDisplayLength', ARGS_TYPE_INT, 0, array('gtzero' => FALSE)), 'iSortCol_0' => $this->_post_args('iSortCol_0', ARGS_TYPE_STRING), 'iSortingCols' => $this->_post_args('iSortingCols', ARGS_TYPE_INT), 'sSearch' => $this->_post_args('sSearch', ARGS_TYPE_STRING), 'sEcho' => $this->_post_args('sEcho', ARGS_TYPE_STRING), 'company_id' => $this->current_user->group_id == 1 ? $this->_post_args('company_id', ARGS_TYPE_INT, $company_id, array('override' => TRUE)) : $this->current_user->company_id, 'group_id' => $this->_post_args('group_id', ARGS_TYPE_INT));
     $qrows = $this->user_m->ajax_gets($input);
     foreach ($qrows['aaData'] as &$qrow) {
         $actions = array('view' => array('href' => site_url('users/show/' . serialize_object(array(SYS_USER_ID => $qrow->user_id))), 'title' => 'User Detail (<small>' . $qrow->full_name . '</small>)', 'text' => 'User Detail', 'params' => 'data-ajax="wdpajax" data-options=\'{"form_method" : "GET", "data_type" : "HTML", "role" : "modal", "created_new" : true, "title" : "User Detail <small>' . $qrow->full_name . '</small>", "modal" : {"buttons" : false, "size" : ""}, "params" : "echo"}\'', 'class' => array()), 'edit' => array('href' => site_url('users/edit/' . serialize_object(array(SYS_USER_ID => $qrow->user_id))), 'title' => 'User Detail (<small>' . $qrow->full_name . '</small>)', 'text' => 'Edit User', 'params' => 'data-ajax="wdpajax" data-options=\'{"form_method" : "GET", "data_type" : "HTML", "role" : "modal", "created_new" : true, "title" : "User Detail <small>' . $qrow->full_name . '</small>", "modal" : {"buttons" : true, "override" : true, "size" : "", "modal_success_callback" : "gl.user.listing.load_grid(g);"}, "params" : "echo", "grid" : {"_init" : true, "gType" : "default"}}\'', 'class' => array()), 'delete' => array('href' => site_url('users/delete/' . serialize_object(array(SYS_USER_ID => $qrow->user_id))), 'title' => 'User <small>' . $qrow->full_name . '</small>', 'text' => 'Delete User', 'params' => 'data-ajax="wdpajax" data-options=\'{"form_method" : "GET", "data_type" : "HTML", "role" : "modal", "created_new" : true, "title" : "User Detail <small>' . $qrow->full_name . '</small>", "modal" : {"buttons" : true, "override" : true, "modal_success_callback" : "gl.user.listing.load_grid(g);"}, "params" : "echo", "grid" : {"_init" : true, "gType" : "default"}}\'', 'class' => array()));
         $qrow = array($qrow->company_name, $qrow->full_name, $qrow->email, $qrow->phone, $qrow->group_description, $qrow->user_id == $this->current_user->user_id ? gtzero_integer($qrow->active) ? 'Active' : 'Inactive' : theme_anchor_button(array('type' => BUTTON_TYPE_ANCHOR, 'href' => gtzero_integer($qrow->active) ? site_url("users/deactivate/" . serialize_object(array(SYS_USER_ID => $qrow->user_id))) : site_url("users/activate/" . serialize_object(array(SYS_USER_ID => $qrow->user_id))), 'title' => gtzero_integer($qrow->active) ? 'De-activate User' : 'Activate User', 'params' => 'data-ajax="wdpajax" data-options=\'{"form_method" : "GET", "data_type" : "HTML", "role" : "modal", "created_new" : true, "title" : "' . (gtzero_integer($qrow->active) ? 'Deactivate' : 'Activate') . ' User <small>' . $qrow->full_name . '</small>", "modal" : {"buttons" : true, "override" : true, "modal_success_callback" : "gl.user.listing.load_grid(g);"}, "params" : "echo", "grid" : {"_init" : true, "gType" : "default"}}\'', 'class' => implode(' ', array(NOICON_BUTTON, gtzero_integer($qrow->active) ? 'btn-success' : 'btn-danger', 'btn-xs btip')), 'icon' => ICON_STATUS_CHANGE . ' mr5', 'text' => gtzero_integer($qrow->active) ? 'Active' : 'Inactive')), local_time($qrow->created_on, 'M d, Y @ h:ia'), $qrow->user_id == $this->current_user->user_id ? '' : theme_button_dropdown($actions));
         if (_check_company_user_access()) {
             unset($qrow[0]);
             $qrow = array_values($qrow);
         }
     }
     echo json_encode($qrows);
 }
示例#6
0
 public function getTable($pkey = '')
 {
     _has_user_access_permission(TRUE, array('admin', 'staff'));
     $params = ($params = unserialize_object($pkey)) && is_array($params) ? $params : array();
     $input = array('iDisplayStart' => $this->_post_args('iDisplayStart', ARGS_TYPE_INT), 'iDisplayLength' => $this->_post_args('iDisplayLength', ARGS_TYPE_INT, 0, array('gtzero' => FALSE)), 'iSortCol_0' => $this->_post_args('iSortCol_0', ARGS_TYPE_STRING), 'iSortingCols' => $this->_post_args('iSortingCols', ARGS_TYPE_INT), 'sSearch' => $this->_post_args('sSearch', ARGS_TYPE_STRING), 'sEcho' => $this->_post_args('sEcho', ARGS_TYPE_STRING));
     $listing = $this->company_m->ajax_get_parts($input);
     foreach ($listing['aaData'] as &$qrow) {
         $company_id = $qrow->company_id;
         $company_name = $qrow->company_name;
         $actions = array();
         $actions['view'] = array('href' => site_url('agencies/show/' . serialize_object(array(SYS_COMPANY_ID => $qrow->company_id))), 'title' => 'Agency Detail (<small>' . $company_name . '</small>)', 'text' => 'Agency Detail', 'params' => 'data-ajax="wdpajax" data-options=\'{"form_method" : "GET", "data_type" : "HTML", "role" : "modal", "created_new" : true, "title" : "Agency Detail <small>' . $company_name . '</small>", "modal" : {"buttons" : false}, "params" : "echo"}\'', 'class' => array());
         if ($this->current_user->group_id == GROUP_ADMIN) {
             $actions['edit'] = array('href' => site_url('agencies/edit/' . serialize_object(array(SYS_COMPANY_ID => $qrow->company_id))), 'title' => 'Agency Detail (<small>' . $company_name . '</small>)', 'text' => 'Edit Agency', 'params' => 'data-ajax="wdpajax" data-options=\'{"form_method" : "GET", "data_type" : "HTML", "role" : "modal", "created_new" : true, "title" : "Agency Detail <small>' . $company_name . '</small>", "modal" : {"buttons" : true, "override" : true, "modal_success_callback" : "updateData();"}, "params" : "echo", "grid" : {"_init" : true, "gType" : "default"}}\'', 'class' => array());
             $actions['delete'] = array('href' => site_url('agencies/delete/' . serialize_object(array(SYS_COMPANY_ID => $qrow->company_id))), 'title' => 'Agency <small>' . $company_name . '</small>', 'text' => 'Delete Agency', 'params' => 'data-ajax="wdpajax" data-options=\'{"form_method" : "GET", "data_type" : "HTML", "role" : "modal", "created_new" : true, "title" : "Agency Detail <small>' . $company_name . '</small>", "modal" : {"buttons" : true, "override" : true, "modal_success_callback" : "updateData();"}, "params" : "echo", "grid" : {"_init" : true, "gType" : "default"}}\'', 'class' => array());
         }
         /*
         if( in_array($this->current_user->group_id, array(GROUP_ADMIN)) ) {
         	$actions['contacts'] = array(
         				'href' 		=> site_url('contacts/index/'.serialize_object(array( SYS_REF_ID => $qrow->company_id, SYS_CONTACT_TYPE_ID => CONTACT_TYPE_COMPANY) )),
         				'title'		=> 'Contacts <small>(Client: '.$company_name.')</small>',
         				'text'		=> 'Contacts',
         				'params'	=> 'data-ajax="wdpajax" data-options=\'{"form_method" : "GET", "data_type" : "HTML", "role" : "modal", "created_new" : true, "title" : "Contacts <small>(Agency: '.$company_name.')</small>", "modal" : {"buttons" : false, "footer" : false, "size" : "modal-lg", "wizard" : true, "override" : true, "nopadd" : false, "modal_before_close_callback" : "gl.contact.listing.close_grid(g);", "callback" : "gl.contact.listing.load_grid(g);"}, "params" : "echo", "grid" : {"_init" : true, "gType" : "next"}}\'',
         				'class'		=> array()
         			);
         
         }
         
         if( in_array($this->current_user->group_id, array(GROUP_ADMIN)) ) {
         	$actions['new_contact'] = array(
         				'href' 		=> site_url('contacts/create/'.serialize_object(array( SYS_REF_ID => $qrow->company_id, SYS_CONTACT_TYPE_ID => CONTACT_TYPE_COMPANY))),
         				'title'		=> 'Contact Detail <small>(Client: '.$company_name.')</small>',
         				'text'		=> 'New Contact',
         				'params'	=> 'data-ajax="wdpajax" data-options=\'{"form_method" : "POST", "data_type" : "HTML", "role" : "modal", "created_new" : true, "title" : "Contact Detail <small>(Agency: '.$company_name.')</small>", "modal" : {"buttons" : true}, "params" : "echo"}\'',
         				'class'		=> array()
         			);
         
         }
         */
         $qrow = array($qrow->company_name, $qrow->address, !empty($qrow->gmt_offset) ? _date_lang_shorttag($qrow->gmt_offset) : '', $this->current_user->group_id == GROUP_ADMIN ? theme_anchor_button(array('type' => BUTTON_TYPE_ANCHOR, 'href' => gtzero_integer($qrow->active) ? site_url("agencies/deactivate/" . serialize_object(array(SYS_COMPANY_ID => $qrow->company_id))) : site_url("agencies/activate/" . serialize_object(array(SYS_COMPANY_ID => $qrow->company_id))), 'title' => gtzero_integer($qrow->active) ? 'De-activate Agency' : 'Activate Agency', 'params' => 'data-ajax="wdpajax" data-options=\'{"form_method" : "GET", "data_type" : "HTML", "role" : "modal", "created_new" : true, "title" : "' . (gtzero_integer($qrow->active) ? 'Deactivate' : 'Activate') . ' Agency <small>' . $company_name . '</small>", "modal" : {"buttons" : true, "override" : true, "modal_success_callback" : "updateData();"}, "params" : "echo", "grid" : {"_init" : true, "gType" : "default"}}\'', 'class' => implode(' ', array(NOICON_BUTTON, gtzero_integer($qrow->active) ? 'btn-success' : 'btn-danger', 'btn-xs btip')), 'icon' => ICON_STATUS_CHANGE . ' mr5', 'text' => gtzero_integer($qrow->active) ? 'Active' : 'Inactive')) : (gtzero_integer($qrow->active) ? 'Active' : 'Inactive'), local_time($qrow->created_on, 'M d, Y @ h:ia'), $qrow->created_by_name, theme_button_dropdown($actions));
     }
     echo json_encode($listing);
 }
<div id="header">
	
	<div id="rpt-title">JOB SHEET</div>
	
    <table class="grid" cellspacing="0" cellpadding="0" width="100%">
	<thead>
		<tr>
			<th width="13%">Job Ref #</th>
			<td width="20%"><?php 
echo $job_info->reference_number;
?>
</td>
			<th width="13%">Date Created</th>
			<td width="21%"><?php 
echo local_time($job_info->created_on, 'd/m/Y');
?>
</td>
			<th width="13%">Created By</th>
			<td width="20%"><?php 
echo $job_info->created_by_name;
?>
</td>
	</tr>
	</thead>
	</table>
</div>

<div id="content">
	<?php 
$this->load->view("web/{$default_theme}/pages/{$page}");
示例#8
0
 public function download($pkey, $method = "echo")
 {
     _has_user_access_permission(TRUE, array('admin'));
     $params = ($params = unserialize_object($pkey)) && is_array($params) ? $params : array();
     $company_id = in_array($this->current_user->group_id, array(GROUP_ADMIN, GROUP_STAFF, GROUP_ENGINEER)) ? $this->_post_args('company_id', ARGS_TYPE_INT, array_key_exists(SYS_COMPANY_ID, $params) && gtzero_integer($params[SYS_COMPANY_ID]) ? to_int($params[SYS_COMPANY_ID]) : 0) : $this->current_user->company_id;
     $site_id = isset($params[SYS_SITE_ID]) && gtzero_integer($params[SYS_SITE_ID]) ? to_int($params[SYS_SITE_ID]) : 0;
     $redirect_url = $this->_post_args('redirect_url', ARGS_TYPE_STRING, $this->agent->referrer());
     $site_statuses = array('' => '', 1 => 'OPEN', 2 => 'SUBMITTED', 3 => 'COMPLETED');
     $site_info = $this->site_m->details($site_id, $company_id);
     if (!$site_info || _has_company_group_access($this->current_user->group_id) && $site_info->company_id != $this->current_user->company_id) {
         $this->show_permission_denied_error($method);
     }
     $company_id = in_array($this->current_user->group_id, array(GROUP_ADMIN, GROUP_STAFF, GROUP_ENGINEER)) ? $this->_post_args('company_id', ARGS_TYPE_INT, $site_info->company_id) : $this->current_user->company_id;
     $doc_key = $this->_post_args('doc_key', ARGS_TYPE_STRING) ? $this->_post_args('doc_key', ARGS_TYPE_STRING) : keygen();
     $csrf = _get_csrf_nonce();
     $headings = array("SITE", "FORM", "DATE ADDED", "ADDED BY", "STATUS", "DATE SUBMITTED", "SUBMITTED BY", "DATE COMPLETED", "COMPLETED BY");
     $this->load->library('PHPExcel');
     $this->load->library('PHPExcel/IOFactory');
     // Create a new PHPExcel object
     $objPHPExcel = new PHPExcel();
     $objPHPExcel->getActiveSheet()->setTitle('List of Site Forms');
     $rowNumber = 1;
     $col = 'A';
     foreach ($headings as $heading) {
         $objPHPExcel->getActiveSheet()->setCellValue($col . $rowNumber, $heading);
         $col++;
     }
     // Loop through the result set
     $rowNumber = 2;
     foreach ($site_info->site_forms as $site_form) {
         $col = 'A';
         $objPHPExcel->getActiveSheet()->setCellValue($col++ . $rowNumber, $site_info->site_code);
         $objPHPExcel->getActiveSheet()->setCellValue($col++ . $rowNumber, $site_form->form_name);
         $objPHPExcel->getActiveSheet()->setCellValue($col++ . $rowNumber, _validate_date($site_form->added_on, 'Y-m-d H:i:s') ? local_time($site_form->added_on, 'M d, Y @ h:ia') : '');
         $objPHPExcel->getActiveSheet()->setCellValue($col++ . $rowNumber, $site_form->added_by_name);
         $objPHPExcel->getActiveSheet()->setCellValue($col++ . $rowNumber, $site_statuses[$site_form->status]);
         $objPHPExcel->getActiveSheet()->setCellValue($col++ . $rowNumber, _validate_date($site_form->submitted_on, 'Y-m-d H:i:s') ? local_time($site_form->submitted_on, 'M d, Y @ h:ia') : '');
         $objPHPExcel->getActiveSheet()->setCellValue($col++ . $rowNumber, $site_form->submitted_by_name);
         $objPHPExcel->getActiveSheet()->setCellValue($col++ . $rowNumber, _validate_date($site_form->completed_on, 'Y-m-d H:i:s') ? local_time($site_form->completed_on, 'M d, Y @ h:ia') : '');
         $objPHPExcel->getActiveSheet()->setCellValue($col++ . $rowNumber, $site_form->completed_by_name);
         $rowNumber++;
     }
     $objWriter = IOFactory::createWriter($objPHPExcel, 'Excel5');
     // We'll be outputting an excel file
     header('Content-type: application/vnd.ms-excel');
     // It will be called file.xls
     header('Content-Disposition: attachment; filename="' . date('Ymd') . '.xls"');
     // Write file to the browser
     $objWriter->save('php://output');
 }
示例#9
0
 /**
  * Get Contents
  *
  * Gets content by filters
  * If an ID or Type ID is present in filters, it will retrieve all content data from the specific content table
  *
  * @param date $filters['start_date'] Only content after this date
  * @param date $filters['end_date'] Only content before this date
  * @param string $filters['author_like'] Only content created by this user (by username, text search)
  * @param int $filters['type'] Only content of this type
  * @param string $filters['title']
  * @param int $filters['id']
  * @param int|array $filters['topic'] Single topic ID or array of multiple topics
  * @param int|array $filters['author'] Single author ID or array of multiple authors
  * @param string $filters['keyword'] A keyword to search the content for (only applies if specifying a content type in $filters['type']).  If selected, each element returns a "relevance" datum.
  * @param string $filters['date_format'] The format to return dates in
  * @param boolean $filters['allow_future'] Allow content from the future?  Default: No/FALSE
  * @param string $filters['sort']
  * @param string $filters['sort_dir']
  * @param int $filters['limit']
  * @param int $filters['offset']
  * @param boolean $counting Set to TRUE to simplify the query and receive a result suitable for counting total records (default: FALSE)
  *
  * @return array Array of content, or FALSE
  */
 function get_contents($filters = array(), $counting = FALSE)
 {
     // cache check!
     if (isset($this->CI->cache) and (!isset($filters['keyword']) and !isset($filters['sort_dir']) or strtolower($filters['sort_dir']) != 'rand()' and strtolower($filters['sort_dir']) != 'random')) {
         $caching = TRUE;
         $cache_key = 'get_contents' . md5(serialize($filters));
         if ($counting == TRUE) {
             $cache_key .= '_counting';
         }
         if ($return = $this->cache->file->get($cache_key)) {
             return $return == 'empty_cache' ? FALSE : $return;
         }
     } else {
         $caching = FALSE;
     }
     // if we are going to do a content search, let's get the total content items so that we can decide
     // if this is a LIKE or a FULLTEXT search
     if (isset($filters['keyword']) and isset($filters['type'])) {
         $content_count = $this->db->query('SELECT COUNT(content_id) AS `content_count` FROM `content` WHERE `content_type_id`=\'' . $filters['type'] . '\'');
         $content_count = $content_count->row()->content_count;
     }
     // do we need to get all content data?  i.e., does it make resource saving sense?
     if (isset($filters['id']) or isset($filters['type'])) {
         // add a hit to the content
         if (isset($filters['id']) && IN_ADMIN === false) {
             $this->add_hit($filters['id']);
         }
         // find out the table name
         if (isset($filters['type'])) {
             $content_type_id = $filters['type'];
         } else {
             $this->db->select('content_type_id');
             $this->db->where('content_id', $filters['id']);
             $result = $this->db->get('content');
             $row = $result->row_array();
             $content_type_id = $row['content_type_id'];
         }
         if (isset($result) and $result->num_rows() == 0) {
             if ($caching == TRUE) {
                 $this->CI->cache->file->save($cache_key, 'empty_cache');
             }
             return FALSE;
         } else {
             $this->load->model('publish/content_type_model');
             $type = $this->content_type_model->get_content_type($content_type_id);
             if (empty($type)) {
                 if ($caching == TRUE) {
                     $this->CI->cache->file->save($cache_key, 'empty_cache');
                 }
                 return FALSE;
             }
             // get custom fields
             $this->load->model('custom_fields_model');
             $custom_fields = $this->custom_fields_model->get_custom_fields(array('group' => $type['custom_field_group_id']));
             // if we are running a keyword search, we need to join the articles table now, unfortunately
             if (isset($filters['keyword'])) {
                 // take care of the select for this specific content type, being careful not to duplicate content_id
                 foreach ($custom_fields as $field) {
                     $this->db->select($type['system_name'] . '.' . $field['name']);
                 }
                 reset($custom_fields);
                 $this->db->join($type['system_name'], 'content.content_id = ' . $type['system_name'] . '.content_id', 'left');
                 $content_table_join = FALSE;
             } else {
                 // join this table into the mix, later
                 $content_table_join = $type['system_name'];
             }
             // are we doing a fulltext search?
             // either a LIKE or FULLTEXT
             if (isset($filters['keyword']) and $content_count > 10) {
                 $search_fields = array();
                 // load fieldtype library for below dbcolumn checks
                 $this->CI->load->library('custom_fields/fieldtype');
                 $search_fields = array();
                 $fields = 1;
                 foreach ($custom_fields as $field) {
                     if ($fields < 16) {
                         // we will only index fields that are VARCHAR, or TEXT
                         $this->CI->fieldtype->load_type($field['type']);
                         $db_column = $this->CI->fieldtype->{$field}['type']->db_column;
                         if (strpos($db_column, 'TEXT') !== FALSE or strpos($db_column, 'VARCHAR') !== FALSE) {
                             $search_fields[] = '`' . $field['name'] . '`';
                             $fields++;
                         }
                     }
                 }
                 reset($custom_fields);
                 $search_fields = implode(', ', $search_fields);
                 $this->db->where('(MATCH (' . $search_fields . ') AGAINST ("' . mysql_real_escape_string($filters['keyword']) . '") OR `content`.`content_title` LIKE \'%' . mysql_real_escape_string($filters['keyword']) . '%\')', NULL, FALSE);
                 $this->db->select('MATCH (' . $search_fields . ') AGAINST ("' . mysql_real_escape_string($filters['keyword']) . '") AS `relevance`', FALSE);
             } elseif (isset($filters['keyword']) and $content_count <= 10) {
                 // we aren't doing a fulltext search, let's get rid of their relevance order
                 if ($filters['sort'] == 'relevance') {
                     unset($filters['sort']);
                 }
                 // search the title
                 $this->db->like('content_title', $filters['keyword']);
                 $search_fields = array();
                 $method = 'or_like';
                 foreach ($custom_fields as $field) {
                     $this->db->{$method}($field['name'], $filters['keyword']);
                 }
                 reset($custom_fields);
             }
         }
     } else {
         // don't join a content type table
         $content_table_join = FALSE;
     }
     if (isset($filters['hits'])) {
         $this->db->where('content.content_hits >=', $filters['hits']);
     }
     if (isset($filters['start_date'])) {
         $start_date = date('Y-m-d H:i:s', strtotime($filters['start_date']));
         $this->db->where('content.content_date >=', $start_date);
     }
     if (isset($filters['end_date'])) {
         $end_date = date('Y-m-d H:i:s', strtotime($filters['end_date']));
         $this->db->where('content.content_date <=', $end_date);
     }
     if (isset($filters['type'])) {
         $this->db->where('content.content_type_id', $filters['type']);
     }
     if (isset($filters['id'])) {
         $this->db->where('content.content_id', $filters['id']);
     }
     if (isset($filters['is_standard'])) {
         $this->db->where('content.content_is_standard', $filters['is_standard']);
     }
     if (isset($filters['title'])) {
         $this->db->like('content.content_title', $filters['title']);
     }
     if (isset($filters['author'])) {
         if (!is_array($filters['author'])) {
             $this->db->where('content.user_id', $filters['author']);
         } else {
             $this->db->where_in('content.user_id', $filters['author']);
         }
     }
     if (isset($filters['topic'])) {
         if (!is_array($filters['topic'])) {
             $this->db->join('topic_maps', 'topic_maps.content_id = content.content_id');
             $this->db->where('topic_maps.topic_id', $filters['topic']);
         } else {
             $this->db->join('topic_maps', 'topic_maps.content_id = content.content_id');
             $this->db->where_in('topic_maps.topic_id', $filters['topic']);
         }
     }
     // will we allow future content?
     if (!isset($filters['allow_future']) or $filters['allow_future'] != TRUE) {
         $this->db->where('content.content_date <', date('Y-m-d H:i:s'));
     }
     // standard ordering and limiting
     $order_by = isset($filters['sort']) ? $filters['sort'] : 'content.content_id';
     $order_dir = isset($filters['sort_dir']) ? $filters['sort_dir'] : 'DESC';
     // are we going to limit in the subquery?  this is more efficient, but not possible if we haven't JOINed the content table
     // we'll check to see if we are sorting by a content field
     if (strpos($order_by, 'content') === 0) {
         // note: in order to retrieve the content in random order, you must pass
         // "random" as the order!
         $order_dir = strtolower($order_dir) == 'rand()' ? 'random' : $order_dir;
         $this->db->order_by($order_by, $order_dir);
         if (isset($filters['limit'])) {
             $offset = isset($filters['offset']) ? $filters['offset'] : 0;
             $this->db->limit($filters['limit'], $offset);
         }
     }
     $this->db->from('content');
     if ($counting == FALSE) {
         // we want to select everything from the content database
         $this->db->select('content.*');
         // if we are dipping into the specific content db (e.g., `articles), we're taking
         // care of that select above
         // get the query we've been building for the embedded select, then clear the active record
         // query being built
         $embedded_from_query = $this->db->_compile_select();
         $this->db->_reset_select();
     } else {
         $this->db->select('content.content_id');
         $result = $this->db->get();
         $rows = $result->num_rows();
         $result->free_result();
         if ($caching == TRUE) {
             $this->CI->cache->file->save($cache_key, $rows, 30 * 60);
         }
         return $rows;
     }
     // this filter has to be applied late, because the users table needs to be joined
     if (isset($filters['author_like'])) {
         $this->db->like('users.user_username', $filters['author_like']);
     }
     // allow them to pass filters that are custom fields
     // this filter must also be passed after we join
     if (isset($custom_fields) and is_array($custom_fields)) {
         foreach ($custom_fields as $field) {
             if (isset($filters[$field['name']])) {
                 if (!empty($filters[$field['name']])) {
                     // they are searching for *something*
                     $this->db->like($field['name'], $filters[$field['name']]);
                 } else {
                     // they are searching for *nothing*
                     $this->db->where($field['name'], $filters[$field['name']]);
                 }
             } elseif (isset($filters[$type['system_name'] . '.' . $field['name']])) {
                 if (!empty($filters[$type['system_name'] . '.' . $field['name']])) {
                     // they are searching for *something*
                     $this->db->like($type['system_name'] . '.' . $field['name'], $filters[$type['system_name'] . '.' . $field['name']]);
                 } else {
                     // they are searching for *nothing*
                     $this->db->where($type['system_name'] . '.' . $field['name'], $filters[$type['system_name'] . '.' . $field['name']]);
                 }
             }
         }
         reset($custom_fields);
     }
     // let's check to see if we should order by/limit this query
     // this only happens if we didn't limit in the subquery (above), i.e., if we are sorting by a content-specific
     // field
     if (strpos($order_by, 'content') !== 0) {
         // note: in order to retrieve the content in random order, you must pass
         // "random" as the order!
         $order_dir = strtolower($order_dir) == 'rand()' ? 'random' : $order_dir;
         $this->db->order_by($order_by, $order_dir);
         if (isset($filters['limit'])) {
             $offset = isset($filters['offset']) ? $filters['offset'] : 0;
             $this->db->limit($filters['limit'], $offset);
         }
     }
     $this->db->join('users', 'users.user_id = content.user_id', 'left');
     $this->db->join('content_types', 'content_types.content_type_id = content.content_type_id', 'left');
     $this->db->join('links', 'links.link_id = content.link_id', 'left');
     if ($content_table_join !== FALSE) {
         $this->db->join($content_table_join, 'content.content_id = ' . $content_table_join . '.content_id', 'left');
     }
     if (IN_ADMIN === false) {
         $this->db->where('content.content_status', 'Enabled');
     }
     $this->db->select('* FROM (' . $embedded_from_query . ') AS `content`', FALSE);
     $result = $this->db->get();
     if ($result->num_rows() == 0) {
         if ($caching == TRUE) {
             $this->CI->cache->file->save($cache_key, 'empty_cache');
         }
         return FALSE;
     }
     $date_format = isset($filters['date_format']) ? $filters['date_format'] : FALSE;
     $contents = array();
     foreach ($result->result_array() as $content) {
         $this_content = array('id' => $content['content_id'], 'link_id' => $content['link_id'], 'date' => local_time($content['content_date'], $date_format), 'end_date' => local_time($content['content_unpublish_date'], $date_format), 'status' => $content['content_status'], 'modified_date' => local_time($content['content_modified'], $date_format), 'author_id' => $content['user_id'], 'author_username' => $content['user_username'], 'author_first_name' => $content['user_first_name'], 'author_last_name' => $content['user_last_name'], 'author_email' => $content['user_email'], 'type_id' => $content['content_type_id'], 'type_name' => $content['content_type_friendly_name'], 'is_standard' => $content['content_is_standard'] == '1' ? TRUE : FALSE, 'title' => $content['content_is_standard'] == '1' ? $content['content_title'] : 'Entry #' . $content['content_id'], 'url_path' => $content['link_url_path'], 'url' => site_url($content['link_url_path']), 'privileges' => !empty($content['content_privileges']) ? unserialize($content['content_privileges']) : FALSE, 'topics' => !empty($content['content_topics']) ? unserialize($content['content_topics']) : FALSE, 'template' => $content['content_type_template'], 'hits' => $content['content_hits'], 'relevance' => isset($content['relevance']) ? $content['relevance'] : FALSE);
         // are we loading in all content data?
         if (isset($custom_fields) and !empty($custom_fields)) {
             foreach ($custom_fields as $field) {
                 @($this_content[$field['name']] = $content[$field['name']]);
             }
             reset($custom_fields);
         }
         $contents[] = $this_content;
     }
     $result->free_result();
     if ($caching == TRUE) {
         $this->CI->cache->file->save($cache_key, $contents, 5 * 60);
     }
     return $contents;
 }
示例#10
0
 /**
  * Get Users
  *
  * @param int $filters['id'] The user ID to select
  * @param int $filters['group'] The group ID to filter by
  * @param int $filters['suspended'] Set to 1 to retrieve suspended users
  * @param string $filters['email'] The email address to filter by
  * @param string $filters['name'] Search by first and last name
  * @param string $filters['username'] Member username
  * @param string $filters['first_name'] Search by first name
  * @param string $filters['last_name'] Search by last name
  * @param date $filters['signup_start_date'] Select after this signup date
  * @param date $filters['signup_end_date'] Select before this signup date
  * @param string $filters['keyword'] Search by ID, Name, Email, or Username
  * @param string $filters['sort'] Field to sort by
  * @param string $filters['sort_dir'] ASC or DESC
  * @param int $filters['limit'] How many records to retrieve
  * @param int $filters['offset'] Start records retrieval at this record
  * @param boolean $any_status Set to TRUE to allow for deleted users, as well (default: FALSE)
  * @param boolean $counting Should we just count the number of users that match the filters? (default: FALSE)
  *
  * @return array Each user in an array of users
  */
 function get_users($filters = array(), $any_status = FALSE, $counting = FALSE)
 {
     $fields = $this->get_custom_fields();
     // keyword search
     if (isset($filters['keyword'])) {
         $this->db->where('user_deleted', '0');
         $this->db->where('user_id', $filters['keyword']);
         $this->db->or_like('user_username', $filters['keyword']);
         $this->db->or_like('user_email', $filters['keyword']);
         $this->db->or_like('user_last_name', $filters['keyword']);
         $this->db->or_like('user_first_name', $filters['keyword']);
     }
     // other filters
     if (isset($filters['id'])) {
         $this->db->where('user_id', $filters['id']);
     }
     if (isset($filters['group'])) {
         $this->db->where('(user_groups LIKE \'%|' . $filters['group'] . '|%\' or user_groups = \'|' . $filters['group'] . '|\')');
     }
     if (isset($filters['suspended'])) {
         $this->db->where('user_suspended', $filters['suspended']);
     }
     if (isset($filters['email'])) {
         $this->db->like('user_email', $filters['email']);
     }
     if (isset($filters['username'])) {
         $this->db->like('user_username', $filters['username']);
     }
     if (isset($filters['name'])) {
         if (is_numeric($filters['name'])) {
             // we are passed a member id
             $this->db->where('users.user_id', $filters['name']);
         } else {
             $this->db->where('(`user_first_name` LIKE \'%' . mysql_real_escape_string($filters['name']) . '%\' OR `user_last_name` LIKE \'%' . mysql_real_escape_string($filters['name']) . '%\')');
         }
     }
     if (isset($filters['first_name'])) {
         $this->db->like('user_first_name', $filters['first_name']);
     }
     if (isset($filters['last_name'])) {
         $this->db->like('user_last_name', $filters['last_name']);
     }
     if (isset($filters['is_admin'])) {
         $this->db->where('users.user_is_admin', $filters['is_admin']);
     }
     if (isset($filters['signup_date_start'])) {
         $date = date('Y-m-d H:i:s', strtotime($filters['signup_date_start']));
         $this->db->where('users.user_signup_date >=', $date);
     }
     if (isset($filters['signup_date_end'])) {
         $date = date('Y-m-d H:i:s', strtotime($filters['signup_date_end']));
         $this->db->where('users.user_signup_date <=', $date);
     }
     // custom field params
     if (is_array($fields)) {
         foreach ($fields as $field) {
             if (isset($filters[$field['name']])) {
                 $this->db->like('users.' . $field['name'], $filters[$field['name']]);
             }
         }
     }
     if ($any_status == FALSE) {
         $this->db->where('user_deleted', '0');
     }
     // standard ordering and limiting
     if ($counting == FALSE) {
         $order_by = isset($filters['sort']) ? $filters['sort'] : 'user_username';
         $order_dir = isset($filters['sort_dir']) ? $filters['sort_dir'] : 'ASC';
         $this->db->order_by($order_by, $order_dir);
         if (isset($filters['limit'])) {
             $offset = isset($filters['offset']) ? $filters['offset'] : 0;
             $this->db->limit($filters['limit'], $offset);
         }
     }
     if ($counting === TRUE) {
         $this->db->select('users.user_id');
         $result = $this->db->get('users');
         $rows = $result->num_rows();
         $result->free_result();
         return $rows;
     } else {
         $this->db->from('users');
         $result = $this->db->get();
     }
     if ($result->num_rows() == 0) {
         return FALSE;
     }
     // get custom fields
     $CI =& get_instance();
     $CI->load->model('custom_fields_model');
     $custom_fields = $CI->custom_fields_model->get_custom_fields(array('group' => '1'));
     $users = array();
     foreach ($result->result_array() as $user) {
         $groups = explode('|', $user['user_groups']);
         $user_groups = array();
         foreach ($groups as $group) {
             if (!empty($group)) {
                 $user_groups[] = $group;
             }
         }
         $this_user = array('id' => $user['user_id'], 'is_admin' => $user['user_is_admin'] == '1' ? TRUE : FALSE, 'customer_id' => $user['customer_id'], 'salt' => $user['user_salt'], 'usergroups' => $user_groups, 'first_name' => $user['user_first_name'], 'last_name' => $user['user_last_name'], 'username' => $user['user_username'], 'email' => $user['user_email'], 'referrer' => $user['user_referrer'], 'signup_date' => local_time($user['user_signup_date']), 'last_login' => local_time($user['user_last_login']), 'suspended' => $user['user_suspended'] == 1 ? TRUE : FALSE, 'admin_link' => site_url('admincp/users/profile/' . $user['user_id']), 'remember_key' => $user['user_remember_key'], 'validate_key' => $user['user_validate_key'], 'cart' => empty($user['user_cart']) ? FALSE : unserialize($user['user_cart']), 'pending_charge_id' => !empty($user['user_pending_charge_id']) ? $user['user_pending_charge_id'] : FALSE);
         foreach ($custom_fields as $field) {
             $this_user[$field['name']] = $user[$field['name']];
         }
         reset($custom_fields);
         $users[] = $this_user;
     }
     $result->free_result();
     return $users;
 }
示例#11
0
 /**
  * Get Responses
  *
  * @param int $filters['form_id'] - Required
  * @param int $filters['limit']
  * @param int $filters['response_id']
  * @param string $filters['start_date']
  * @param string $filters['end_date']
  * @param string $filters['username']
  *
  * @return array responses
  */
 function get_responses($filters = array())
 {
     if (!isset($filters['form_id'])) {
         die(show_error('Form ID is required in get_responses.'));
     }
     $form = $this->get_form($filters['form_id']);
     if (empty($form)) {
         return FALSE;
     }
     if (isset($filters['response_id'])) {
         $this->db->where($form['table_name'] . '_id', $filters['response_id']);
     }
     if (isset($filters['start_date'])) {
         $start_date = date('Y-m-d H:i:s', strtotime($filters['start_date']));
         $this->db->where('submission_date >=', $start_date);
     }
     if (isset($filters['end_date'])) {
         $end_date = date('Y-m-d H:i:s', strtotime($filters['end_date']));
         $this->db->where('submission_date <=', $end_date);
     }
     if (isset($filters['username'])) {
         $this->db->like('users.user_username', $filters['username']);
     }
     $this->db->order_by('submission_date', 'DESC');
     // standard ordering and limiting
     $order_by = isset($filters['sort']) ? $filters['sort'] : $form['table_name'] . '.submission_date';
     $order_dir = isset($filters['sort_dir']) ? $filters['sort_dir'] : 'DESC';
     $this->db->order_by($order_by, $order_dir);
     if (isset($filters['limit'])) {
         $offset = isset($filters['offset']) ? $filters['offset'] : 0;
         $this->db->limit($filters['limit'], $offset);
     }
     $this->db->join('users', 'users.user_id = ' . $form['table_name'] . '.user_id', 'LEFT');
     $result = $this->db->get($form['table_name']);
     if ($result->num_rows() == 0) {
         return FALSE;
     }
     $responses = array();
     foreach ($result->result_array() as $row) {
         $this_response = array('id' => $row[$form['table_name'] . '_id'], 'form_id' => $form['id'], 'submission_date' => local_time($row['submission_date']), 'user_id' => $row['user_id']);
         // member data?
         if (!empty($row['user_id'])) {
             $this_response['member_username'] = $row['user_username'];
             $this_response['member_first_name'] = $row['user_first_name'];
             $this_response['member_last_name'] = $row['user_last_name'];
             $this_response['member_email'] = $row['user_email'];
             $this_response['member_signup_date'] = local_time($row['user_signup_date']);
         }
         // custom field data
         foreach ($form['custom_fields'] as $field) {
             $this_response[$field['name']] = $row[$field['name']];
         }
         $responses[] = $this_response;
     }
     return $responses;
 }
        ?>
			<li class="new">
				<span class="desc"  style="margin-left:0;">
					<span class="name"><?php 
        echo anchor_popup('job/show/' . $message->ref_id, !empty($message->job_ref) ? $message->job_ref : $message->ref_id, $popup_atts);
        ?>
 </span>
					<span class="msg"><?php 
        echo $message->note;
        ?>
</span>
				</span>
				<span class="clearfix mt10" style="display:block">
					<span class="pull-left" style="line-height:normal;">
						<?php 
        echo local_time($message->date_created, 'M d, Y @ H:i');
        ?>
					</span>
					<span class="pull-right" style="line-height:normal;">
						<a href="<?php 
        echo site_url('logs/notes/update_remedial_notes/' . $message->id);
        ?>
" title="Verify that you have dealt with this issue" class="tip" data-ajax="wdpajax" data-options='{"params" : "ajax", "success_callback" : "wdp.update_remedial_notification(response, form)"}' style="white-space:normal;">
							<span class="badge badge-success"><i class="glyphicon glyphicon-ok" style="margin-right:5px;"> </i>Mark as actioned</span>
						</a>
					</span>
				</span>
			</li>
			<?php 
    }
} else {
示例#13
0
 /**
  * Search subscriptions.
  *
  * Returns an array of results based on submitted search criteria.  All fields are optional.
  *
  * @param int $params['gateway_id'] The gateway ID used for the order. Optional.
  * @param date $params['created_after'] Only subscriptions created after or on this date will be returned. Optional.
  * @param date $params['created_before'] Only subscriptions created before or on this date will be returned. Optional.
  * @param int $params['customer_id'] The customer id associated with the subscription. Optional.
  * @param string $params['customer_internal_id'] The customer's internal id associated with the subscription. Optional.
  * @param int $params['amount'] Only subscriptions for this amount will be returned. Optional.
  * @param boolean $params['active'] Returns only active subscriptions. Optional.
  * @param int $params['plan_id'] Only return subscriptions link to this plan ID
  * @param int $params['offset'] Offsets the database query.
  * @param int $params['limit'] Limits the number of results returned. Optional.
  * @param string $params['sort'] Variable used to sort the results.  Possible values are date, customer_first_name, customer_last_name, amount. Optional
  * @param string $params['sort_dir'] Used when a sort param is supplied.  Possible values are asc and desc. Optional.
  * 
  * @return mixed Array containing results
  */
 function GetRecurrings($params, $any_status = FALSE)
 {
     // Check which search paramaters are set
     if (isset($params['id'])) {
         $this->db->where('subscription_id', $params['id']);
     }
     if (isset($params['gateway_id'])) {
         $this->db->where('gateway_id', $params['gateway_id']);
     }
     if (isset($params['created_after'])) {
         $start_date = date('Y-m-d H:i:s', strtotime($params['created_after']));
         $this->db->where('timestamp >=', $start_date);
     }
     if (isset($params['created_before'])) {
         $end_date = date('Y-m-d H:i:s', strtotime($params['created_before']));
         $this->db->where('timestamp <=', $end_date);
     }
     if (isset($params['customer_id'])) {
         $this->db->where('subscriptions.customer_id', $params['customer_id']);
     }
     if (isset($params['customer_last_name'])) {
         $this->db->where('customers.last_name', $params['customer_last_name']);
     }
     if (isset($params['customer_internal_id'])) {
         $this->db->where('customers.internal_id', $params['customer_internal_id']);
     }
     if (isset($params['amount'])) {
         $this->db->where('amount', $params['amount']);
     }
     if (isset($params['active'])) {
         if ($params['active'] == '1' or $params['active'] == '0') {
             $this->db->where('subscriptions.active', $params['active']);
         }
     } elseif ($any_status == FALSE) {
         $this->db->where('subscriptions.active', '1');
     }
     if (isset($params['plan_id'])) {
         $this->db->where('subscriptions.plan_id', $params['plan_id']);
     }
     if (isset($params['offset'])) {
         $offset = $params['offset'];
     } else {
         $offset = 0;
     }
     if (isset($params['limit'])) {
         $this->db->limit($params['limit'], $offset);
     }
     if (isset($params['sort_dir']) and ($params['sort_dir'] == 'asc' or $params['sort_dir'] == 'desc')) {
         $sort_dir = $params['sort_dir'];
     } else {
         $sort_dir = 'desc';
     }
     $params['sort'] = isset($params['sort']) ? $params['sort'] : '';
     switch ($params['sort']) {
         case 'date':
             $sort = 'subscription_id';
             break;
         case 'customer_first_name':
             $sort = 'first_name';
             break;
         case 'customer_last_name':
             $sort = 'last_name';
             break;
         case 'amount':
             $sort = 'amount';
             break;
         default:
             $sort = 'subscription_id';
             break;
     }
     $this->db->order_by($sort, $sort_dir);
     $this->db->join('customers', 'customers.customer_id = subscriptions.customer_id', 'left');
     $this->db->join('countries', 'countries.country_id = customers.country', 'left');
     $this->db->join('plans', 'plans.plan_id = subscriptions.plan_id', 'left');
     $this->db->join('plan_types', 'plan_types.plan_type_id = plans.plan_type_id', 'left');
     $this->db->select('subscriptions.*');
     $this->db->select('subscriptions.active AS sub_active');
     $this->db->select('customers.*');
     $this->db->select('countries.*');
     $this->db->select('plans.name');
     $this->db->select('plan_types.type AS plan_type', false);
     $this->db->select('plans.interval AS plan_interval', false);
     $this->db->select('plans.amount AS plan_amount', false);
     $this->db->select('plans.notification_url AS plan_notification_url', false);
     $query = $this->db->get('subscriptions');
     $data = array();
     if ($query->num_rows() > 0) {
         $i = 0;
         foreach ($query->result() as $row) {
             $data[$i]['id'] = $row->subscription_id;
             $data[$i]['gateway_id'] = $row->gateway_id;
             $data[$i]['date_created'] = local_time($row->timestamp);
             $data[$i]['amount'] = money_format("%!^i", $row->amount);
             $data[$i]['interval'] = $row->charge_interval;
             $data[$i]['start_date'] = local_time($row->start_date);
             $data[$i]['end_date'] = local_time($row->end_date);
             $data[$i]['last_charge_date'] = local_time($row->last_charge);
             $data[$i]['renewed'] = $row->renewed;
             $data[$i]['updated'] = $row->updated;
             $data[$i]['next_charge_date'] = strtotime($row->next_charge) < strtotime($row->end_date) ? local_time($row->next_charge) : local_time($row->end_date);
             if ($row->sub_active == '0' and $row->cancel_date == '0000-00-00 00:00:00') {
                 // this sub never even started
                 $data[$i]['cancel_date'] = local_time($row->start_date);
             } elseif ($row->sub_active == '0') {
                 $data[$i]['cancel_date'] = local_time($row->cancel_date);
             }
             $data[$i]['number_occurrences'] = $row->number_occurrences;
             $data[$i]['notification_url'] = $row->notification_url;
             $data[$i]['status'] = $row->sub_active == '1' ? 'active' : 'inactive';
             $data[$i]['card_last_four'] = $row->card_last_four;
             if ($row->customer_id !== 0) {
                 $data[$i]['customer']['customer_id'] = $row->customer_id;
                 $data[$i]['customer']['id'] = $row->customer_id;
                 $data[$i]['customer']['internal_id'] = $row->internal_id;
                 $data[$i]['customer']['first_name'] = $row->first_name;
                 $data[$i]['customer']['last_name'] = $row->last_name;
                 $data[$i]['customer']['company'] = $row->company;
                 $data[$i]['customer']['address_1'] = $row->address_1;
                 $data[$i]['customer']['address_2'] = $row->address_2;
                 $data[$i]['customer']['city'] = $row->city;
                 $data[$i]['customer']['state'] = $row->state;
                 $data[$i]['customer']['postal_code'] = $row->postal_code;
                 $data[$i]['customer']['country'] = $row->iso2;
                 $data[$i]['customer']['email'] = $row->email;
                 $data[$i]['customer']['phone'] = $row->phone;
             }
             if ($row->plan_id != 0) {
                 $data[$i]['plan']['id'] = $row->plan_id;
                 $data[$i]['plan']['type'] = $row->plan_type;
                 $data[$i]['plan']['name'] = $row->name;
                 $data[$i]['plan']['amount'] = money_format("%!^i", $row->plan_amount);
                 $data[$i]['plan']['interval'] = $row->plan_interval;
                 $data[$i]['plan']['notification_url'] = $row->plan_notification_url;
             }
             $i++;
         }
     } else {
         return FALSE;
     }
     return $data;
 }
示例#14
0
					<?php 
        foreach ($params['por_rows'] as $por_row) {
            ?>
					<li>
						<span class="desc" style="margin-left:0;">
							<span class="msg">
								<strong><small>Job ID : </small></strong><small><?php 
            echo $por_row->job_id;
            ?>
</small><br />
								<strong><small>Requested By : </small></strong><small><?php 
            echo $por_row->requested_by_name;
            ?>
</small><br />
								<strong><small>Requested On : </small></strong><small><?php 
            echo local_time($por_row->requested_on, 'M d, Y @ h:ia');
            ?>
</small><br />
							</span>
						</span>
						<span class="pull-right" style="line-height:normal;">
						
							<?php 
            foreach ($por_row->files as $attachment) {
                ?>
							<?php 
                $cdn_file = cdn_url() . DOCUMENT_FOLDER . $attachment->document_name;
                $file_headers = @get_headers($cdn_file, 1);
                $is_document_exist = strpos($file_headers[0], '404 Not Found') === FALSE && strpos($file_headers[0], '403 Forbidden') === FALSE ? TRUE : FALSE;
                if ($is_document_exist) {
                    ?>
示例#15
0
 /**
  * Get Subscriptions
  *
  * Returns an array of results based on submitted search criteria.
  *
  * @param int $filters['id'] The subscription ID
  * @param string $filters['status'] One of "recurring", "will_expire", "expired", "renewed", "updated"
  * @param int $filters['gateway_id'] The gateway ID used for the order. Optional.
  * @param date $filters['created_after'] Only subscriptions created after or on this date will be returned. Optional.
  * @param date $filters['created_before'] Only subscriptions created before or on this date will be returned. Optional.
  * @param date $filters['end_date_after'] Only subscriptions ending after or on this date will be returned. Optional.
  * @param date $filters['end_date_before'] Only subscriptions ending before or on this date will be returned. Optional.
  * @param int $filters['user_id'] The customer id associated with the subscription. Optional.
  * @param int $filters['amount'] Only subscriptions for this amount will be returned. Optional.
  * @param boolean $filters['active'] Returns only active subscriptions. Optional.
  * @param int $filters['plan_id'] Only return subscriptions link to this subscription_plan_id. Optional.
  * @param int $filters['offset'] Offsets the database query.
  * @param int $filters['limit'] Limits the number of results returned. Optional.
  * @param string $filters['sort'] Variable used to sort the results.  Possible values are date, customer_first_name, customer_last_name, amount. Optional
  * @param string $filters['sort_dir'] Used when a sort param is supplied.  Possible values are asc and desc. Optional.
  *
  * @return mixed Array containing results
  */
 public function get_subscriptions($filters, $counting = FALSE)
 {
     if (isset($filters['id'])) {
         $this->db->where('subscription_id', $filters['id']);
     }
     if (isset($filters['gateway_id'])) {
         $this->db->where('gateway_id', $filters['gateway_id']);
     }
     if (isset($filters['created_after'])) {
         $start_date = date('Y-m-d', strtotime($filters['created_after']));
         $this->db->where('timestamp >=', $start_date);
     }
     if (isset($filters['created_before'])) {
         $end_date = date('Y-m-d', strtotime($filters['created_before']));
         $this->db->where('timestamp <=', $end_date);
     }
     if (isset($filters['end_date_after'])) {
         $end_date = date('Y-m-d H:i:s', strtotime($filters['end_date_after']));
         $this->db->where('end_date >=', $end_date);
         $this->db->where('end_date !=', '0000-00-00');
     }
     if (isset($filters['end_date_before'])) {
         $end_date = date('Y-m-d H:i:s', strtotime($filters['end_date_before']));
         $this->db->where('end_date <=', $end_date);
         $this->db->where('end_date !=', '0000-00-00');
     }
     if (isset($filters['cancel_date_after'])) {
         $end_date = date('Y-m-d H:i:s', strtotime($filters['cancel_date_after']));
         $this->db->where('cancel_date >=', $end_date);
         $this->db->where('cancel_date !=', '0000-00-00');
     }
     if (isset($filters['cancel_date_before'])) {
         $end_date = date('Y-m-d H:i:s', strtotime($filters['cancel_date_before']));
         $this->db->where('cancel_date <=', $end_date);
         $this->db->where('cancel_date !=', '0000-00-00');
     }
     if (isset($filters['user_id'])) {
         $this->db->where('users.user_id', $filters['user_id']);
         // if we are loading subs for a user, we assume we only want subs that are "completed" (i.e., fully set up)
         $this->db->where('completed', '1');
     }
     if (isset($filters['member_name'])) {
         if (is_numeric($filters['member_name'])) {
             // we are passed a member id
             $this->db->where('users.user_id', $filters['member_name']);
         } else {
             $this->db->like('users.user_last_name', $filters['member_name']);
         }
     }
     if (isset($filters['amount'])) {
         $this->db->where('subscriptions.amount', $filters['amount']);
     }
     if (isset($filters['active'])) {
         $this->db->where('subscriptions.active', $filters['active']);
     }
     if (isset($filters['plan_id'])) {
         $this->db->where('subscription_plans.subscription_plan_id', $filters['plan_id']);
     }
     if (isset($filters['promotion'])) {
         $this->db->where('subscription_plans.subscription_plan_promotion', $filters['promotion']);
     }
     if (isset($filters['expiry_processed'])) {
         $this->db->where('subscriptions.expiry_processed', $filters['expiry_processed']);
     }
     if (isset($filters['status'])) {
         if ($filters['status'] == 'recurring') {
             $this->db->where('subscriptions.active', '1');
             $this->db->where('subscriptions.end_date >', date('Y-m-d'));
         } elseif ($filters['status'] == 'will_expire') {
             $this->db->where('subscriptions.active', '0');
             $this->db->where('subscriptions.end_date >', date('Y-m-d'));
         } elseif ($filters['status'] == 'expired') {
             $this->db->where('subscriptions.end_date <', date('Y-m-d'));
             $this->db->where('subscriptions.renewed', '0');
             $this->db->where('subscriptions.updated', '0');
         } elseif ($filters['status'] == 'renewed') {
             $this->db->where('subscriptions.renewed !=', '0');
         } elseif ($filters['status'] == 'updated') {
             $this->db->where('subscriptions.updated !=', '0');
         }
     }
     // standard ordering and limiting
     $order_by = isset($filters['sort']) ? $filters['sort'] : 'subscriptions.subscription_id';
     $order_dir = isset($filters['sort_dir']) ? $filters['sort_dir'] : 'DESC';
     $this->db->order_by($order_by, $order_dir);
     if (isset($filters['limit'])) {
         $offset = isset($filters['offset']) ? $filters['offset'] : 0;
         $this->db->limit($filters['limit'], $offset);
     }
     $this->db->join('customers', 'customers.customer_id = subscriptions.customer_id', 'inner');
     $this->db->join('users', 'users.user_id = customers.internal_id', 'inner');
     $this->db->join('plans', 'plans.plan_id = subscriptions.plan_id', 'inner');
     $this->db->join('subscription_plans', 'subscription_plans.plan_id = plans.plan_id');
     $this->db->join('plan_types', 'plan_types.plan_type_id = plans.plan_type_id', 'inner');
     if ($counting == FALSE) {
         $this->db->select('subscriptions.*');
         $this->db->select('subscriptions.active AS sub_active');
         $this->db->select('subscription_plans.subscription_plan_id');
         $this->db->select('users.*');
         $this->db->select('plans.name');
         $this->db->select('plan_types.type AS plan_type', false);
         $this->db->select('plans.interval AS plan_interval', false);
         $this->db->select('plans.amount AS plan_amount', false);
         $result = $this->db->get('subscriptions');
     } else {
         $this->db->select('COUNT(`subscriptions`.`subscription_id`) AS `counted`', FALSE);
         $result = $this->db->get('subscriptions');
         $count = $result->row_array();
         return $count['counted'];
     }
     if ($result->num_rows() == 0) {
         return FALSE;
     }
     $subscriptions = array();
     foreach ($result->result_array() as $subscription) {
         $this_subscription = array('id' => $subscription['subscription_id'], 'user_id' => $subscription['user_id'], 'user_username' => $subscription['user_username'], 'user_first_name' => $subscription['user_first_name'], 'user_last_name' => $subscription['user_last_name'], 'user_email' => $subscription['user_email'], 'gateway_id' => $subscription['gateway_id'], 'date_created' => local_time($subscription['timestamp']), 'amount' => money_format("%!^i", $subscription['amount']), 'interval' => $subscription['charge_interval'], 'start_date' => local_time($subscription['start_date']), 'end_date' => $subscription['end_date'] != '0000-00-00' ? local_time($subscription['end_date']) : FALSE, 'last_charge_date' => $subscription['last_charge'] != '0000-00-00' ? local_time($subscription['last_charge']) : FALSE, 'next_charge_date' => (strtotime($subscription['next_charge']) < strtotime($subscription['end_date']) and $subscription['next_charge'] != '0000-00-00') ? local_time($subscription['next_charge']) : FALSE, 'cancel_date' => $subscription['cancel_date'] != '0000-00-00' ? local_time($subscription['cancel_date']) : FALSE, 'number_occurrences' => $subscription['number_occurrences'], 'active' => $subscription['sub_active'] == '1' ? TRUE : FALSE, 'coupon_id' => $subscription['coupon_id'], 'renewing_subscription_id' => $subscription['renewed'], 'updating_subscription_id' => $subscription['updated'], 'card_last_four' => !empty($subscription['card_last_four']) ? $subscription['card_last_four'] : FALSE, 'plan_id' => $subscription['subscription_plan_id'], 'renew_link' => site_url('billing/subscriptions/renew/' . $subscription['subscription_id']), 'cancel_link' => site_url('users/cancel/' . $subscription['subscription_id']), 'update_cc_link' => !empty($subscription['card_last_four']) ? site_url('users/update_cc/' . $subscription['subscription_id']) : FALSE, 'is_recurring' => ($subscription['sub_active'] == '1' and strtotime($subscription['end_date']) > strtotime($subscription['next_charge'])) ? TRUE : FALSE, 'is_active' => (strpos($subscription['end_date'], '0000-00-00') === TRUE or strtotime($subscription['end_date']) > time()) ? TRUE : FALSE, 'is_renewed' => empty($subscription['renewed']) ? FALSE : TRUE, 'is_updated' => empty($subscription['updated']) ? FALSE : TRUE);
         if ($subscription['sub_active'] == '0' and $subscription['cancel_date'] == '0000-00-00 00:00:00') {
             // this sub never even started
             $this_subscription['cancel_date'] = local_time($subscription['start_date']);
         } elseif (empty($subscription['sub_active'])) {
             $this_subscription['cancel_date'] = local_time($subscription['cancel_date']);
         }
         if (!empty($subscription['plan_id'])) {
             $this_subscription['plan']['id'] = $subscription['plan_id'];
             $this_subscription['plan']['type'] = $subscription['plan_type'];
             $this_subscription['plan']['name'] = $subscription['name'];
             $this_subscription['plan']['amount'] = money_format("%!^i", $subscription['plan_amount']);
             $this_subscription['plan']['interval'] = $subscription['plan_interval'];
         }
         $subscriptions[] = $this_subscription;
     }
     return $subscriptions;
 }
示例#16
0
 /**
  * View Invoices
  *
  * Returns an array of results based on submitted search criteria.  All fields are optional.
  *
  * @param int $filters['user_id'] Member ID
  * @param date $filters['start_date'] Only orders after or on this date will be returned. Optional.
  * @param date $filters['end_date'] Only orders before or on this date will be returned. Optional.
  * @param int $filters['id'] The charge ID.  Optional.
  * @param string $filters['amount'] The amount of the charge.  Optional.
  * @param boolean $filters['subscription_id'] Only charges linked to this subscription.
  * @param int $filters['card_last_four'] Last 4 digits of credit card
  * @param int $filters['offset'] Offsets the database query.
  * @param int $filters['limit'] Limits the number of results returned. Optional.
  * @param string $filters['sort'] Column used to sort the results.
  * @param string $filters['sort_dir'] Used when a sort param is supplied.  Possible values are asc and desc. Optional.
  * @param boolean $counting Set to TRUE to receive the total number of matching invoices
  *
  * @return array|bool Invoice results or FALSE if none
  */
 function get_invoices($filters, $counting = FALSE)
 {
     if (isset($filters['start_date'])) {
         $start_date = date('Y-m-d H:i:s', strtotime($filters['start_date']));
         $this->db->where('timestamp >=', $start_date);
     }
     if (isset($filters['end_date'])) {
         $end_date = date('Y-m-d H:i:s', strtotime($filters['end_date']));
         $this->db->where('timestamp <=', $end_date);
     }
     if (isset($filters['amount'])) {
         $this->db->where('orders.amount', $filters['amount']);
     }
     if (isset($filters['id'])) {
         $this->db->where('orders.order_id', $filters['id']);
     }
     if (isset($filters['customer_id'])) {
         $this->db->where('orders.customer_id', $filters['customer_id']);
     }
     if (isset($filters['user_id'])) {
         $this->db->where('customers.internal_id', $filters['user_id']);
     }
     if (isset($filters['gateway'])) {
         $this->db->like('gateways.gateway_id', $filters['gateway']);
     }
     if (isset($filters['member_name'])) {
         if (is_numeric($filters['member_name'])) {
             // we are passed a member id
             $this->db->where('users.user_id', $filters['member_name']);
         } else {
             $this->db->like('users.user_last_name', $filters['member_name']);
         }
     }
     if (isset($filters['subscription_id'])) {
         $this->db->where('orders.subscription_id', $filters['subscription_id']);
     }
     if (isset($filters['card_last_four'])) {
         $this->db->where('orders.card_last_four', $filters['card_last_four']);
     }
     if (isset($filters['status'])) {
         $this->db->where('orders.status', $filters['status']);
     } else {
         $this->db->where('orders.status', '1');
     }
     if (isset($filters['refunded']) and $filters['refunded'] == TRUE) {
         $this->db->where('orders.refunded', '1');
     }
     // standard ordering and limiting
     $order_by = isset($filters['sort']) ? $filters['sort'] : 'orders.order_id';
     $order_dir = isset($filters['sort_dir']) ? $filters['sort_dir'] : 'DESC';
     $this->db->order_by($order_by, $order_dir);
     if (isset($filters['limit'])) {
         $offset = isset($filters['offset']) ? $filters['offset'] : 0;
         $this->db->limit($filters['limit'], $offset);
     }
     $this->db->join('customers', 'customers.customer_id = orders.customer_id', 'inner');
     $this->db->join('users', 'customers.internal_id = users.user_id', 'inner');
     $this->db->join('countries', 'countries.country_id = customers.country', 'left');
     $this->db->join('gateways', 'gateways.gateway_id = orders.gateway_id', 'left');
     $this->db->join('order_details', 'order_details.order_id = orders.order_id', 'left');
     $this->db->join('taxes_received', 'orders.order_id = taxes_received.order_id', 'left');
     $this->db->join('taxes', 'taxes.tax_id = taxes_received.tax_id', 'left');
     $this->db->join('shipping_received', 'orders.order_id = shipping_received.order_id', 'left');
     $this->db->join('shipping', 'shipping.shipping_id = shipping_received.shipping_id', 'left');
     $this->db->join('coupons', 'order_details.coupon_id = coupons.coupon_id', 'left');
     $this->db->group_by('orders.order_id');
     if ($counting == TRUE) {
         $this->db->select('orders.order_id');
         $result = $this->db->get('orders');
         $total_rows = $result->num_rows();
         $result->free_result();
         return $total_rows;
     } else {
         $this->db->select('*');
         $this->db->select('orders.order_id AS invoice_id');
         $this->db->select('orders.subscription_id AS true_subscription_id');
     }
     $this->db->from('orders');
     $result = $this->db->get();
     if ($result->num_rows() == 0) {
         return FALSE;
     }
     //	die('<pre>'. print_r($result->result(), true));
     $invoices = array();
     foreach ($result->result_array() as $invoice) {
         $t = array('id' => $invoice['invoice_id'], 'gateway_id' => $invoice['gateway_id'], 'gateway' => $invoice['alias'], 'date' => local_time($invoice['timestamp']), 'user_id' => $invoice['user_id'], 'user_first_name' => $invoice['user_first_name'], 'user_last_name' => $invoice['user_last_name'], 'user_email' => $invoice['user_email'], 'user_groups' => $invoice['user_groups'], 'amount' => money_format("%!^i", (double) $invoice['amount']), 'refunded' => $invoice['refunded'] == '1' ? TRUE : FALSE, 'card_last_four' => $invoice['card_last_four'], 'is_refunded' => empty($invoice['refunded']) ? FALSE : TRUE, 'refund_date' => empty($invoice['refunded']) ? FALSE : local_time($invoice['refund_date']), 'subscription_id' => $invoice['true_subscription_id'], 'tax_name' => empty($invoice['tax_name']) ? FALSE : $invoice['tax_name'], 'tax_paid' => money_format("%!^i", (double) ($invoice['tax_received_for_products'] + $invoice['tax_received_for_subscription'])), 'tax_rate' => empty($invoice['tax_percentage']) ? FALSE : $invoice['tax_percentage'], 'shipping_id' => !empty($invoice['shipping_id']) ? $invoice['shipping_id'] : FALSE, 'shipping_name' => !empty($invoice['shipping_name']) ? $invoice['shipping_name'] : 'Default', 'shipping_charge' => !empty($invoice['shipping_received_amount']) ? money_format("%!^i", (double) $invoice['shipping_received_amount']) : FALSE, 'order_details_id' => !empty($invoice['order_details_id']) ? $invoice['order_details_id'] : FALSE, 'coupon_name' => !empty($invoice['coupon_name']) ? $invoice['coupon_name'] : FALSE, 'coupon_code' => !empty($invoice['coupon_code']) ? $invoice['coupon_code'] : FALSE, 'coupon_id' => !empty($invoice['coupon_id']) ? $invoice['coupon_id'] : FALSE, 'billing_address' => array('first_name' => $invoice['first_name'], 'last_name' => $invoice['last_name'], 'company' => $invoice['company'], 'address_1' => $invoice['address_1'], 'address_2' => $invoice['address_2'], 'city' => $invoice['city'], 'state' => $invoice['state'], 'country' => $invoice['iso2'], 'postal_code' => $invoice['postal_code'], 'email' => $invoice['email'], 'phone_number' => $invoice['phone']));
         // If we're using a dynamic shipping module, then we might
         // have a better description of the name we can use.
         if (isset($invoice['shipping_desc']) && !empty($invoice['shipping_desc'])) {
             $t['shipping_name'] = $invoice['shipping_desc'];
         }
         // If there's any chance a module was associated with this order, send that along
         if (isset($invoice['module']) && !empty($invoice['module'])) {
             $t['module'] = $invoice['module'];
         }
         $invoices[] = $t;
     }
     return $invoices;
 }
示例#17
0
文件: bydate.php 项目: BGmot/kitchen
</tr></table>-->
<?php 
require 'menu_inc.php';
$end_timestamp = microtime(true);
$duration = $end_timestamp - $start_timestamp;
?>


<br><b><?php 
print $max_id - $last_id;
?>
</b> new message(s) since you came here last time
&nbsp;&nbsp;&nbsp;&nbsp;Queried: <?php 
printf(' (in ' . round($duration, 5) . ' seconds) <b>');
//print(date('Y F d H:i:s', time()));
print local_time(time(), 'Y F d H:i:s');
?>
</b><br>
<ol>
<?php 
print $out;
?>
</ol>
<form target="contents" method=POST action="<?php 
print $root_dir . $page_bydate;
?>
">
<?php 
if (strlen($err) > 0) {
    print '<br><font color="red"><b>' . $err . '</b></font></br>';
}
示例#18
0
    echo $site_form->added_by_name;
    ?>
</td>
								<td><?php 
    echo $site_statuses[$site_form->status];
    ?>
</td>
								<?php 
    /*<td><?php echo local_time($site_form->submitted_on,'M d, Y @ h:ia');?></td>*/
    ?>
								<td><?php 
    echo $site_form->submitted_by_name;
    ?>
</td>
								<td><?php 
    echo local_time($site_form->completed_on, 'M d, Y @ h:ia');
    ?>
</td>
								<?php 
    /*<td><?php echo $site_form->completed_by_name;?></td>*/
    ?>
								<td>
									<a href="<?php 
    echo site_url('sites/feedback/' . serialize_object(array(SYS_SITE_FORM_ID => $site_form->id, SYS_SITE_ID => $site_form->site_id, SYS_FORM_TYPE_ID => $site_form->form_type_id)));
    ?>
" class="btn btn-xs btn-warning"><i class="fa fa-eye"></i></a>
									<?php 
    if ($current_user->group_id == GROUP_ADMIN) {
        ?>
									<a href="<?php 
        echo site_url('sites/sfstatus/' . serialize_object(array(SYS_SITE_FORM_ID => $site_form->id, SYS_SITE_ID => $site_form->site_id, SYS_FORM_TYPE_ID => $site_form->form_type_id)));
示例#19
0
 /**
  * Get a list of customer details.
  *
  * Searches the database for customers belonging to the client and returns an array with all the details.
  * All search parameters are optional.
  *
  * @param string $params['internal_id'] Customer's internal ID. Optional.
  * @param string $params['first_name'] Customer's first name. Optional.
  * @param string $params['last_name'] Customer's last name. Optional.
  * @param string $params['company'] Customer's company. Optional.
  * @param string $params['address_1'] Customer's address line 1. Optional.
  * @param string $params['address_2'] Customer's address line 2. Optional.
  * @param string $params['city'] Customer's city. Optional.
  * @param string $params['state'] Customer's state. Optional.
  * @param string $params['postal_code'] Customer's postal code. Optional. 
  * @param string $params['country'] Customer's country. Optional.
  * @param string $params['phone'] Customer's phone. Optional.
  * @param string $params['email'] Customer's email. Optional.
  * @param int $params['plan_id'] Filter by active plan. Optional.
  * @param int $params['deleted'] Set to 1 for deleted customers.  Optional.
  * @param string $pararms['sort'] Used to change the order of results returned.  Possible values are date, first_name, and last_name. Optional.
  * @param string $params['sort_dir'] Used only when a sort valus is padded.  Possible values are asc and desc
  * 
  * @return mixed Array containing the search results
  */
 function GetCustomers($params, $any_status = FALSE)
 {
     if (isset($params['deleted']) and $params['deleted'] == '1') {
         $this->db->where('customers.active', '0');
     } elseif ($any_status == FALSE) {
         $this->db->where('customers.active', '1');
     }
     // Check which search paramaters are set
     if (isset($params['first_name'])) {
         $this->db->where('first_name', $params['first_name']);
     }
     if (isset($params['internal_id'])) {
         $this->db->where('internal_id', $params['internal_id']);
     }
     if (isset($params['id'])) {
         $this->db->where('customers.customer_id', $params['id']);
     }
     if (isset($params['customer_id'])) {
         $this->db->where('customers.customer_id', $params['customer_id']);
     }
     if (isset($params['last_name'])) {
         $this->db->where('last_name', $params['last_name']);
     }
     if (isset($params['company'])) {
         $this->db->where('company', $params['company']);
     }
     if (isset($params['address_1'])) {
         $this->db->where('address_1', $params['address_1']);
     }
     if (isset($params['address_2'])) {
         $this->db->where('address_2', $params['address_2']);
     }
     if (isset($params['city'])) {
         $this->db->where('city', $params['city']);
     }
     if (isset($params['state'])) {
         $this->db->where('state', $params['state']);
     }
     if (isset($params['postal_code'])) {
         $this->db->where('postal_code', $params['postal_code']);
     }
     if (isset($params['country'])) {
         $this->db->where('country', $params['country']);
     }
     if (isset($params['phone'])) {
         $this->db->where('phone', $params['phone']);
     }
     if (isset($params['email'])) {
         $this->db->where('email', $params['email']);
     }
     if (isset($params['offset'])) {
         $offset = $params['offset'];
     } else {
         $offset = 0;
     }
     if (isset($params['limit'])) {
         $this->db->limit($params['limit'], $offset);
     }
     $params['sort'] = isset($params['sort']) ? $params['sort'] : '';
     switch ($params['sort']) {
         case 'date':
             $sort = 'date_created';
             break;
         case 'first_name':
             $sort = 'first_name';
             break;
         case 'last_name':
             $sort = 'last_name';
             break;
         default:
             $sort = 'last_name';
             break;
     }
     $params['sort_dir'] = isset($params['sort_dir']) ? $params['sort_dir'] : '';
     switch ($params['sort_dir']) {
         case 'asc':
             $sort_dir = 'ASC';
             break;
         case 'desc':
             $sort_dir = 'DESC';
             break;
         default:
             $sort_dir = 'DESC';
             break;
     }
     $this->db->order_by($sort, $sort_dir);
     if (isset($params['active_recurring']) or isset($params['plan_id'])) {
         $this->db->join('subscriptions', 'customers.customer_id = subscriptions.customer_id', 'left');
     }
     if (isset($params['active_recurring'])) {
         if ($params['active_recurring'] == 1) {
             $this->db->where('subscriptions.active', 1);
         } elseif ($params['active_recurring'] === 0) {
             $this->db->where('subscriptions.active', 0);
         }
     }
     if (isset($params['plan_id'])) {
         $this->db->where('subscriptions.plan_id', $params['plan_id']);
         $this->db->where('subscriptions.active', '1');
     }
     $this->db->select('customers.*');
     $this->db->select('countries.iso2');
     $this->db->join('countries', 'countries.country_id = customers.country', 'left');
     $this->db->group_by('customers.customer_id');
     $query = $this->db->get('customers');
     $data = array();
     if ($query->num_rows() > 0) {
         $i = 0;
         foreach ($query->result() as $row) {
             $data[$i]['id'] = $row->customer_id;
             $data[$i]['internal_id'] = $row->internal_id;
             $data[$i]['first_name'] = $row->first_name;
             $data[$i]['last_name'] = $row->last_name;
             $data[$i]['company'] = $row->company;
             $data[$i]['address_1'] = $row->address_1;
             $data[$i]['address_2'] = $row->address_2;
             $data[$i]['city'] = $row->city;
             $data[$i]['state'] = $row->state;
             $data[$i]['postal_code'] = $row->postal_code;
             $data[$i]['country'] = $row->iso2;
             $data[$i]['email'] = $row->email;
             $data[$i]['phone'] = $row->phone;
             $data[$i]['date_created'] = local_time($row->date_created);
             $data[$i]['status'] = $row->active == 1 ? 'active' : 'deleted';
             $plans = $this->GetPlansByCustomer($row->customer_id);
             if (!empty($plans)) {
                 $n = 0;
                 foreach ($plans as $plan) {
                     $data[$i]['plans'][$n]['id'] = $plan['id'];
                     $data[$i]['plans'][$n]['name'] = $plan['name'];
                     $data[$i]['plans'][$n]['amount'] = $plan['amount'];
                     $data[$i]['plans'][$n]['interval'] = $plan['interval'];
                     $data[$i]['plans'][$n]['notification_url'] = $plan['notification_url'];
                     $data[$i]['plans'][$n]['status'] = $plan['active'];
                     $n++;
                 }
             }
             $i++;
         }
     } else {
         return FALSE;
     }
     return $data;
 }
示例#20
0
 /**
  * Get Order Products
  *
  * Get all product orders as individual prodects, with filters.  Instead of retrieving individual
  * orders, this method will retrieve 3 records for 1 order of 3 products.
  *
  * @param date $filters['start_date']
  * @param date $filters['end_date']
  * @param float $filters['amount']
  * @param int $filters['invoice_id']
  * @param int $filters['customer_id']
  * @param int $filters['user_id']
  * @param int $filters['gateway']
  * @param string $filters['member_name']
  * @param boolean $filters['refunded']
  * @param string $filters['product_name']
  * @param boolean $filters['shipped']
  * @param string $filters['sort']
  * @param string $filters['sort_dir']
  * @param int $filters['limit']
  * @param int $filters['offset']
  *
  * @return array Product/order records
  */
 function get_order_products($filters = array())
 {
     if (isset($filters['start_date'])) {
         $start_date = date('Y-m-d H:i:s', strtotime($filters['start_date']));
         $this->db->where('orders.timestamp >=', $start_date);
     }
     if (isset($filters['end_date'])) {
         $end_date = date('Y-m-d H:i:s', strtotime($filters['end_date']));
         $this->db->where('orders.timestamp <=', $end_date);
     }
     if (isset($filters['amount'])) {
         $this->db->where('orders.amount', $filters['amount']);
     }
     if (isset($filters['invoice_id'])) {
         $this->db->where('orders.order_id', $filters['invoice_id']);
     }
     if (isset($filters['customer_id'])) {
         $this->db->where('orders.customer_id', $filters['customer_id']);
     }
     if (isset($filters['user_id'])) {
         $this->db->where('customers.internal_id', $filters['user_id']);
     }
     if (isset($filters['gateway'])) {
         $this->db->like('gateways.gateway_id', $filters['gateway']);
     }
     if (isset($filters['member_name'])) {
         $this->db->like('users.user_last_name', $filters['member_name']);
     }
     if (isset($filters['refunded']) and $filters['refunded'] == TRUE) {
         $this->db->where('orders.refunded', '1');
     }
     if (isset($filters['product_name'])) {
         $this->db->like('products.product_name', $filters['product_name']);
     }
     if (isset($filters['shipped'])) {
         if ($filters['shipped'] == TRUE) {
             $filters['shipped'] = '1';
         } else {
             $filters['shipped'] = '0';
         }
         $this->db->where('order_products.order_products_shipped', $filters['shipped']);
     }
     // standard ordering and limiting
     $order_by = isset($filters['sort']) ? $filters['sort'] : 'orders.order_id';
     $order_dir = isset($filters['sort_dir']) ? $filters['sort_dir'] : 'DESC';
     $this->db->order_by($order_by, $order_dir);
     if (isset($filters['limit'])) {
         $offset = isset($filters['offset']) ? $filters['offset'] : 0;
         $this->db->limit($filters['limit'], $offset);
     }
     $this->db->where('orders.status', '1');
     $this->db->select('*');
     $this->db->select('orders.order_id AS invoice_id');
     $this->db->join('customers', 'customers.customer_id = orders.customer_id', 'inner');
     $this->db->join('users', 'customers.internal_id = users.user_id', 'inner');
     $this->db->join('countries', 'countries.country_id = customers.country', 'left');
     $this->db->join('gateways', 'gateways.gateway_id = orders.gateway_id', 'left');
     $this->db->join('order_details', 'order_details.order_id = orders.order_id', 'inner');
     $this->db->join('order_products', 'order_details.order_details_id = order_products.order_details_id', 'inner');
     $this->db->join('products', 'products.product_id = order_products.product_id', 'inner');
     $this->db->join('taxes_received', 'orders.order_id = taxes_received.order_id', 'left');
     $this->db->join('taxes', 'taxes.tax_id = taxes_received.tax_id', 'left');
     $this->db->join('shipping_received', 'orders.order_id = shipping_received.order_id', 'left');
     $this->db->join('shipping', 'shipping.shipping_id = shipping_received.shipping_id', 'left');
     $this->db->group_by('order_products.order_products_id');
     $this->db->from('orders');
     $result = $this->db->get();
     if ($result->num_rows() == 0) {
         return FALSE;
     }
     $products = array();
     foreach ($result->result_array() as $product) {
         if (!empty($product['shipping_first_name'])) {
             $shipping_address = array('first_name' => $product['shipping_first_name'], 'last_name' => $product['shipping_last_name'], 'company' => $product['shipping_company'], 'address_1' => $product['shipping_address_1'], 'address_2' => $product['shipping_address_2'], 'city' => $product['shipping_city'], 'state' => $product['shipping_state'], 'country' => $product['shipping_country'], 'postal_code' => $product['shipping_postal_code'], 'phone_number' => $product['shipping_phone_number']);
         } else {
             $shipping_address = FALSE;
         }
         $products[] = array('invoice_id' => $product['invoice_id'], 'order_products_id' => $product['order_products_id'], 'name' => $product['product_name'], 'quantity' => $product['order_products_quantity'], 'price' => money_format("%!^i", $product['order_products_price']), 'shipped' => $product['order_products_shipped'] == '1' ? TRUE : FALSE, 'options' => !empty($product['order_products_options']) ? unserialize($product['order_products_options']) : FALSE, 'gateway_id' => $product['gateway_id'], 'gateway' => $product['alias'], 'date' => local_time($product['timestamp']), 'user_id' => $product['user_id'], 'user_first_name' => $product['user_first_name'], 'user_last_name' => $product['user_last_name'], 'user_email' => $product['user_email'], 'user_groups' => $product['user_groups'], 'amount' => money_format("%!^i", (double) $product['amount']), 'refunded' => $product['refunded'] == '1' ? TRUE : FALSE, 'card_last_four' => $product['card_last_four'], 'is_refunded' => empty($product['refunded']) ? FALSE : TRUE, 'refund_date' => empty($product['refunded']) ? FALSE : local_time($product['refund_date']), 'tax_name' => empty($product['tax_name']) ? FALSE : $product['tax_name'], 'tax_paid' => money_format("%!^i", (double) ($product['tax_received_for_products'] + $product['tax_received_for_subscription'])), 'tax_rate' => empty($product['tax_percentage']) ? FALSE : $product['tax_percentage'], 'shipping_id' => !empty($product['shipping_id']) ? $product['shipping_id'] : FALSE, 'shipping_name' => !empty($product['shipping_name']) ? $product['shipping_name'] : 'Default', 'shipping_charge' => !empty($product['shipping_received_amount']) ? money_format("%!^i", (double) $product['shipping_received_amount']) : FALSE, 'order_details_id' => !empty($product['order_details_id']) ? $product['order_details_id'] : FALSE, 'shipping_address' => $shipping_address, 'billing_address' => array('first_name' => $product['first_name'], 'last_name' => $product['last_name'], 'company' => $product['company'], 'address_1' => $product['address_1'], 'address_2' => $product['address_2'], 'city' => $product['city'], 'state' => $product['state'], 'country' => $product['iso2'], 'postal_code' => $product['postal_code'], 'email' => $product['email'], 'phone_number' => $product['phone']));
     }
     return $products;
 }
示例#21
0
 /**
  * Search Orders.
  *
  * Returns an array of results based on submitted search criteria.  All fields are optional.
  *
  * @param int $client_id The client ID.
  * @param int $params['gateway_id'] The gateway ID used for the order. Optional.
  * @param date $params['start_date'] Only orders after or on this date will be returned. Optional.
  * @param date $params['end_date'] Only orders before or on this date will be returned. Optional.
  * @param int $params['customer_id'] The customer id associated with the order. Optional.
  * @param string $params['customer_internal_id'] The customer's internal id associated with the order. Optional.
  * @param int $params['id'] The charge ID.  Optional.
  * @param string $params['amount'] The amount of the charge.  Optional.
  * @param string $params['customer_last_name'] The last name of the customer.  Optional.
  * @param int $params['status'] Set to ok/failed to filter results.  Optional.
  * @param boolean $params['recurring_only'] Returns only orders that are part of a recurring subscription. Optional.
  * @param int $params['offset'] Offsets the database query.
  * @param int $params['card_last_four'] Last 4 digits of credit card
  * @param int $params['limit'] Limits the number of results returned. Optional.
  * @param string $params['sort'] Variable used to sort the results.  Possible values are date, customer_first_name, customer_last_name, amount. Optional
  * @param string $params['sort_dir'] Used when a sort param is supplied.  Possible values are asc and desc. Optional.
  *
  * @return array|bool Charge results or FALSE upon failure
  */
 function GetCharges($client_id, $params)
 {
     // Make sure they only get their own charges
     $this->db->where('orders.client_id', $client_id);
     // Check which search paramaters are set
     if (isset($params['gateway_id'])) {
         $this->db->where('orders.gateway_id', $params['gateway_id']);
     }
     $this->load->library('field_validation');
     if (isset($params['start_date'])) {
         $valid_date = $this->field_validation->ValidateDate($params['start_date']);
         if (!$valid_date) {
             die($this->response->Error(5007));
         }
         $start_date = date('Y-m-d H:i:s', strtotime($params['start_date']));
         $this->db->where('orders.timestamp >=', $start_date);
     }
     if (isset($params['end_date'])) {
         $valid_date = $this->field_validation->ValidateDate($params['start_date']);
         if (!$valid_date) {
             die($this->response->Error(5007));
         }
         $end_date = date('Y-m-d H:i:s', strtotime($params['end_date']));
         $this->db->where('orders.timestamp <=', $end_date);
     }
     if (isset($params['customer_id'])) {
         $this->db->where('orders.customer_id', $params['customer_id']);
     }
     if (isset($params['amount'])) {
         $this->db->where('orders.amount', $params['amount']);
     }
     if (isset($params['id'])) {
         $this->db->where('orders.order_id', $params['id']);
     }
     if (isset($params['customer_id'])) {
         $this->db->where('orders.customer_id', $params['customer_id']);
     }
     if (isset($params['customer_last_name'])) {
         $this->db->like('customers.last_name', $params['customer_last_name']);
     }
     if (isset($params['customer_internal_id'])) {
         $this->db->where('customers.internal_id', $params['customer_internal_id']);
     }
     if (isset($params['recurring_only']) && $params['recurring_only'] == 1) {
         $this->db->where('orders.subscription_id <>', 0);
     }
     if (isset($params['recurring_id'])) {
         $this->db->where('orders.subscription_id', $params['recurring_id']);
     }
     if (isset($params['card_last_four'])) {
         $this->db->where('orders.card_last_four', $params['card_last_four']);
     }
     if (isset($params['status'])) {
         if ($params['status'] == '1' or $params['status'] == 'ok') {
             $this->db->where('orders.status', '1');
             $this->db->where('orders.refunded', '0');
         } elseif ($params['status'] == '2' or $params['status'] == 'refunded') {
             $this->db->where('orders.refunded', '1');
         } elseif ($params['status'] == '3' or $params['status'] == 'failed_repeat') {
             $this->db->where('orders.status', '0');
             $this->db->where('orders.subscription_id !=', '0');
             $this->db->where('subscriptions.start_date !=', 'subscriptions.end_date', FALSE);
         } else {
             $this->db->where('orders.status', '0');
         }
     }
     if (isset($params['offset'])) {
         $offset = $params['offset'];
     } else {
         $offset = 0;
     }
     if (isset($params['limit'])) {
         $this->db->limit($params['limit'], $offset);
     }
     if (isset($params['sort_dir']) and ($params['sort_dir'] == 'asc' or $params['sort_dir'] == 'desc')) {
         $sort_dir = $params['sort_dir'];
     } else {
         $sort_dir = 'DESC';
     }
     $params['sort'] = isset($params['sort']) ? $params['sort'] : '';
     switch ($params['sort']) {
         case 'date':
             $sort = 'orders.timestamp';
             break;
         case 'customer_first_name':
             $sort = 'customers.first_name';
             break;
         case 'customer_last_name':
             $sort = 'customers.last_name';
             break;
         case 'amount':
             $sort = 'orders.amount';
             break;
         default:
             $sort = 'orders.timestamp';
             break;
     }
     $sort_dir = isset($params['sort_dir']) ? $params['sort_dir'] : 'DESC';
     $this->db->order_by($sort, $sort_dir);
     $this->db->select('customers.*');
     $this->db->select('countries.*');
     $this->db->select('orders.*');
     $this->db->select('coupons.coupon_code AS coupon_code');
     $this->db->select('subscriptions.start_date');
     $this->db->join('customers', 'customers.customer_id = orders.customer_id', 'left');
     $this->db->join('countries', 'countries.country_id = customers.country', 'left');
     $this->db->join('subscriptions', 'subscriptions.subscription_id = orders.subscription_id', 'left');
     $this->db->join('coupons', 'coupons.coupon_id = orders.coupon_id', 'left');
     $query = $this->db->get('orders');
     $data = array();
     if ($query->num_rows() > 0) {
         $i = 0;
         foreach ($query->result() as $row) {
             $data[$i]['id'] = $row->order_id;
             $data[$i]['gateway_id'] = $row->gateway_id;
             $data[$i]['date'] = local_time($client_id, $row->timestamp);
             $data[$i]['amount'] = money_format("%!^i", (double) $row->amount);
             $data[$i]['card_last_four'] = $row->card_last_four;
             $data[$i]['status'] = $row->status == '1' ? 'ok' : 'failed';
             $data[$i]['refunded'] = $row->refunded;
             if ($row->refunded == '1') {
                 $data[$i]['refund_date'] = local_time($client_id, $row->refund_date);
             }
             if ($row->subscription_id != 0) {
                 $data[$i]['recurring_id'] = $row->subscription_id;
             }
             // was this a recurring charge (other than the first charge)
             if ($row->subscription_id != 0 and date('Y-m-d', strtotime($row->start_date)) != date('Y-m-d', strtotime($row->timestamp))) {
                 $data[$i]['type'] = 'recurring_repeat';
             } elseif ($row->subscription_id != 0) {
                 $data[$i]['type'] = 'recurring_charge';
             } else {
                 $data[$i]['type'] = 'single_charge';
             }
             $data[$i]['coupon'] = isset($row->coupon_code) ? $row->coupon_code : '';
             if ($row->customer_id != 0) {
                 $data[$i]['customer']['id'] = $row->customer_id;
                 $data[$i]['customer']['internal_id'] = $row->internal_id;
                 $data[$i]['customer']['first_name'] = $row->first_name;
                 $data[$i]['customer']['last_name'] = $row->last_name;
                 $data[$i]['customer']['company'] = $row->company;
                 $data[$i]['customer']['address_1'] = $row->address_1;
                 $data[$i]['customer']['address_2'] = $row->address_2;
                 $data[$i]['customer']['city'] = $row->city;
                 $data[$i]['customer']['state'] = $row->state;
                 $data[$i]['customer']['country'] = $row->iso2;
                 $data[$i]['customer']['postal_code'] = $row->postal_code;
                 $data[$i]['customer']['email'] = $row->email;
                 $data[$i]['customer']['phone'] = $row->phone;
                 $data[$i]['customer']['date_created'] = local_time($client_id, $row->date_created);
                 $data[$i]['customer']['status'] = $row->active == 1 ? 'active' : 'deleted';
             }
             $i++;
         }
     } else {
         return FALSE;
     }
     return $data;
 }
示例#22
0
 function get_logins($filters = array())
 {
     if (isset($filters['id'])) {
         $this->db->where('user_login_id', $filters['id']);
     }
     if (isset($filters['user_id'])) {
         $this->db->where('user_logins.user_id', $filters['user_id']);
     }
     if (isset($filters['username'])) {
         $this->db->where('user_username', $filters['username']);
     }
     if (isset($filters['group_id'])) {
         $this->db->where('(user_groups LIKE \'%|' . $filters['group'] . '|%\' or user_groups = \'|' . $filters['group'] . '|\')');
     }
     if (isset($filters['ip'])) {
         $this->db->like('user_login_ip', $filters['ip']);
     }
     if (isset($filters['browser'])) {
         $this->db->like('user_login_browser', $filters['browser']);
     }
     if (isset($filters['start_date']) and isset($filters['end_date'])) {
         // got a date range
         $this->db->where('user_login_date >=', date('Y-m-d H:i:s', strtotime($filters['start_date'])));
         $this->db->where('user_login_date <=', date('Y-m-d H:i:s', strtotime($filters['end_date'])));
     }
     // standard ordering and limiting
     $order_by = isset($filters['sort']) ? $filters['sort'] : 'user_login_id';
     $order_dir = isset($filters['sort_dir']) ? $filters['sort_dir'] : 'DESC';
     $this->db->order_by($order_by, $order_dir);
     if (isset($filters['limit'])) {
         $offset = isset($filters['offset']) ? $filters['offset'] : 0;
         $this->db->limit($filters['limit'], $offset);
     }
     $this->db->join('users', 'users.user_id = user_logins.user_id');
     $result = $this->db->get('user_logins');
     if ($result->num_rows() == 0) {
         return FALSE;
     } else {
         $logins = array();
         foreach ($result->result_array() as $login) {
             $groups = explode('|', $login['user_groups']);
             $user_groups = array();
             foreach ($groups as $group) {
                 if (!empty($group)) {
                     $user_groups[] = $group;
                 }
             }
             $logins[] = array('id' => $login['user_login_id'], 'user_id' => $login['user_id'], 'date' => local_time($login['user_login_date']), 'ip' => $login['user_login_ip'], 'browser' => $login['user_login_browser'], 'username' => $login['user_username'], 'email' => $login['user_email'], 'usergroups' => $user_groups);
         }
         return $logins;
     }
 }