function __construct() { parent::__construct(); $this->view_data['core_settings'] = Setting::first(); if ($this->input->cookie('language') != "") { $language = $this->input->cookie('language'); } else { if (isset($this->view_data['language'])) { $language = $this->view_data['language']; } else { if (!empty($this->view_data['core_settings']->language)) { $language = $this->view_data['core_settings']->language; } else { $language = "english"; } } } $this->lang->load('application', $language); $this->lang->load('messages', $language); $this->lang->load('event', $language); $this->user = $this->session->userdata('user_id') ? User::find_by_id($this->session->userdata('user_id')) : FALSE; $this->client = $this->session->userdata('client_id') ? Client::find_by_id($this->session->userdata('client_id')) : FALSE; if ($this->client) { $this->theme_view = 'application_client'; } $this->view_data['datetime'] = date('Y-m-d H:i', time()); $this->view_data['sticky'] = Project::all(array('conditions' => 'sticky = 1')); $this->view_data['quotations_new'] = Quote::find_by_sql("select count(id) as amount from quotations where status='New'"); if ($this->user || $this->client) { $access = $this->user ? $this->user->access : $this->client->access; $access = explode(",", $access); if ($this->user) { $this->view_data['menu'] = Module::find('all', array('order' => 'sort asc', 'conditions' => array('id in (?) AND type = ?', $access, 'main'))); $this->view_data['widgets'] = Module::find('all', array('conditions' => array('id in (?) AND type = ?', $access, 'widget'))); } else { $this->view_data['menu'] = Module::find('all', array('order' => 'sort asc', 'conditions' => array('id in (?) AND type = ?', $access, 'client'))); } if ($this->user) { $update = User::find($this->user->id); } else { $update = Client::find($this->client->id); } $update->last_active = time(); $update->save(); if ($this->user) { $this->view_data['user_online'] = User::all(array('conditions' => array('last_active+(30 * 60) > ? AND status = ?', time(), "active"))); $this->view_data['client_online'] = Client::all(array('conditions' => array('last_active+(30 * 60) > ? AND inactive = ?', time(), "0"))); } $email = $this->user ? 'u' . $this->user->id : 'c' . $this->client->id; $this->view_data['messages_new'] = Privatemessage::find_by_sql("select count(id) as amount from privatemessages where `status`='New' AND recipient = '" . $email . "'"); $this->view_data['tickets_new'] = Ticket::find_by_sql("select count(id) as amount from tickets where `status`='New'"); } /*$this->load->database(); $sql = "select * FROM templates WHERE type='notes'"; $query = $this->db->query($sql); */ $this->view_data["note_templates"] = ""; //$query->result(); }
function index() { if ($this->user->admin == 1) { $settings = Setting::first(); $this->load->helper('curl'); $object = remote_get_contents('http://fc2.luxsys-apps.com/updates/xml.php?code=' . $settings->pc); $object = json_decode($object); $this->view_data['update'] = FALSE; if (isset($object->error)) { if ($object->error == FALSE && $object->lastupdate > $settings->version) { $this->view_data['update'] = $object->lastupdate; } } } $year = date('Y', time()); $this->view_data["year"] = $year; $thismonth = date('m'); $this->view_data["month"] = date('M'); $tax = $this->view_data['core_settings']->tax; //calculate stats $result = Invoice::find_by_sql("SELECT paid_date, SUM(`sum`) AS summary FROM `invoices` WHERE estimate != 1 AND status = 'Paid' AND paid_date between '{$year}-01-01' AND '{$year}-12-31' GROUP BY SUBSTR(paid_date,1,7)"); $this->view_data["stats"] = $result; //Projects //open $this->view_data["projects_open"] = Project::count(array('conditions' => array('progress < ?', 100))); //all $this->view_data["projects_all"] = Project::count(); //invoices //open $this->view_data["invoices_open"] = Invoice::count(array('conditions' => array('status != ? AND estimate != ?', 'Paid', 1))); //all $this->view_data["invoices_all"] = Invoice::count(array('conditions' => array('estimate != ?', 1))); //payments open $result = Invoice::find_by_sql("SELECT SUM(`sum`) AS summary FROM `invoices` WHERE estimate != 1 AND status = 'Paid' AND paid_date between '{$year}-{$thismonth}-01' AND '{$year}-{$thismonth}-31'"); $this->view_data["payments"] = $result; //payments outstanding $result = Invoice::find_by_sql("SELECT SUM(`sum`) AS summary FROM `invoices` WHERE estimate != 1 AND status != 'Paid'"); $this->view_data["paymentsoutstanding"] = $result; //Events $events = array(); $date = date('Y-m-d', time()); $eventcount = 0; foreach ($this->view_data['menu'] as $key => $value) { if ($value->link == "invoices") { $sql = 'SELECT * FROM invoices WHERE status != "Paid" AND due_date < "' . $date . '" AND estimate != 1 ORDER BY due_date'; $res = Invoice::find_by_sql($sql); //$res = $res->result(); foreach ($res as $key2 => $value2) { $eventline = str_replace("{invoice_number}", '<a href="' . base_url() . 'invoices/view/' . $value2->id . '">#' . $value2->reference . '</a>', $this->lang->line('event_invoice_overdue')); $events[$value2->due_date . "." . $value2->id] = $eventline; $eventcount = $eventcount + 1; } } if ($value->link == "projects") { $sql = 'SELECT * FROM projects WHERE progress != "100" AND end < "' . $date . '" ORDER BY end'; $res = Project::find_by_sql($sql); //$res = $res->result(); foreach ($res as $key2 => $value2) { if ($this->user->admin == 0) { $sql = "SELECT id FROM `project_has_workers` WHERE project_id = " . $value->id . " AND user_id = " . $this->user->id; $res = Project::find_by_sql($sql); //$res = $query; if ($res) { $eventline = str_replace("{project_number}", '<a href="' . base_url() . 'projects/view/' . $value2->id . '">#' . $value2->reference . '</a>', $this->lang->line('event_project_overdue')); $events[$value2->end . "." . $value2->id] = $eventline; $eventcount = $eventcount + 1; } } else { $eventline = str_replace("{project_number}", '<a href="' . base_url() . 'projects/view/' . $value2->id . '">#' . $value2->reference . '</a>', $this->lang->line('event_project_overdue')); $events[$value2->end . "." . $value2->id] = $eventline; $eventcount = $eventcount + 1; } } } if ($value->link == "subscriptions") { $sql = 'SELECT * FROM subscriptions WHERE status != "Inactive" AND end_date > "' . $date . '" AND next_payment <= "' . $date . '" ORDER BY next_payment'; $res = Subscription::find_by_sql($sql); //$res = $res->result(); foreach ($res as $key2 => $value2) { $eventline = str_replace("{subscription_number}", '<a href="' . base_url() . 'subscriptions/view/' . $value2->id . '">#' . $value2->reference . '</a>', $this->lang->line('event_subscription_new_invoice')); $events[$value2->next_payment . "." . $value2->id] = $eventline; $eventcount = $eventcount + 1; } } if ($value->link == "messages") { $sql = 'SELECT privatemessages.id, privatemessages.`status`, privatemessages.subject, privatemessages.message, privatemessages.`time`, privatemessages.`recipient`, clients.`userpic` as userpic_c, users.`userpic` as userpic_u , users.`email` as email_u , clients.`email` as email_c , CONCAT(users.firstname," ", users.lastname) as sender_u, CONCAT(clients.firstname," ", clients.lastname) as sender_c FROM privatemessages LEFT JOIN clients ON CONCAT("c",clients.id) = privatemessages.sender LEFT JOIN users ON CONCAT("u",users.id) = privatemessages.sender GROUP by privatemessages.id HAVING privatemessages.recipient = "u' . $this->user->id . '"AND privatemessages.status != "deleted" ORDER BY privatemessages.`time` DESC LIMIT 6'; $query = Privatemessage::find_by_sql($sql); $this->view_data["message"] = array_filter($query); } if ($value->link == "projects") { $sql = 'SELECT * FROM project_has_tasks WHERE status != "done" AND user_id = "' . $this->user->id . '" ORDER BY project_id'; $taskquery = Project::find_by_sql($sql); $this->view_data["tasks"] = $taskquery; } } krsort($events); $this->view_data["events"] = $events; $this->view_data["eventcount"] = $eventcount; $this->content_view = 'dashboard/dashboard'; }