public function before() { parent::before(); if (!Group::current('allow_assign')) { throw new HTTP_Exception_403(); } }
public function before() { if (!User::current()) { $this->redirect('/login'); } $url = str_replace('.', '_', URL::base() . $this->request->uri()); if (isset($_GET[$url])) { unset($_GET[$url]); } if (isset($_GET[$url . '/'])) { unset($_GET[$url . '/']); } if (Group::current('is_admin') || Group::current('show_all_jobs') && Group::current('allow_finance')) { Pager::$counts[] = 2500; } if (Arr::get($_GET, 'limit') && in_array($_GET['limit'], Pager::$counts)) { DB::update('users')->set(array('list_items' => intval($_GET['limit'])))->where('id', '=', User::current('id'))->execute(); die(json_encode(array('success' => 'true'))); } if (Arr::get($_GET, 'dismiss')) { DB::delete('notifications')->where('user_id', '=', User::current('id'))->and_where('id', '=', intval($_GET['dismiss']))->execute(); die(json_encode(array('success' => 'true'))); } if (!Group::current('allow_assign')) { Enums::$statuses[Enums::STATUS_UNALLOC] = 'Not active'; } View::set_global('notifications', DB::select()->from('notifications')->where('user_id', '=', User::current('id'))->order_by('id', 'desc')->execute()); }
public function before() { parent::before(); if (!Group::current('allow_finance') || !Group::current('show_all_jobs')) { throw new HTTP_Exception_403('Forbidden'); } }
public function action_index() { $id = intval($this->request->param('id')); $attachment = DB::select()->from('attachments')->where('id', '=', $id)->execute()->current(); if (!preg_match('/^image\\/.*$/i', $attachment['mime']) || $attachment['folder'] == 'Signatures') { throw new HTTP_Exception_403('Forbidden'); } $job = Database_Mongo::collection('jobs')->findOne(array('_id' => strval($attachment['job_id']))); if (!$job) { throw new HTTP_Exception_404('Not found'); } if (!Group::current('show_all_jobs') && !in_array((int) User::current('company_id'), Arr::get($job, 'companies', array()), true) && !in_array((int) User::current('company_id'), Arr::get($job, 'ex', array()), true)) { throw new HTTP_Exception_403('Forbidden'); } if (!file_exists(DOCROOT . 'storage/' . $id)) { throw new HTTP_Exception_404('Not found'); } list(, $data) = explode(',', file_get_contents('php://input'), 2); $src = imagecreatefromstring(file_get_contents(DOCROOT . 'storage/' . $id)); $image = imagecreatefromstring(base64_decode($data)); imagealphablending($src, true); imagesavealpha($src, true); imagecopyresampled($src, $image, 0, 0, 0, 0, imagesx($src), imagesy($src), imagesx($image), imagesy($image)); if ($attachment['mime'] == 'image/png') { imagepng($src, DOCROOT . 'storage/' . $id, 9); } else { imagejpeg($src, DOCROOT . 'storage/' . $id, 90); } if (file_exists(DOCROOT . 'storage/' . $id . '.thumb')) { unlink(DOCROOT . 'storage/' . $id . '.thumb'); } imagedestroy($src); imagedestroy($image); die(json_encode(array('success' => true))); }
public function before() { if (!Group::current('allow_reports')) { throw new HTTP_Exception_403('Forbidden'); } parent::before(); }
public function action_fda() { $query = array(); if (!Group::current('allow_assign')) { $query['$or'] = array(array('companies' => intval(User::current('company_id'))), array('ex' => intval(User::current('company_id')))); } else { if (Arr::get($_GET, 'company')) { $company = is_array($_GET['company']) ? $_GET['company'] : explode(',', $_GET['company']); $company = array_map('intval', $company); if (count($company) == 1) { $company = array_shift($company); } $query['$or'] = array(array('companies' => is_array($company) ? array('$in' => $company) : $company), array('ex' => is_array($company) ? array('$in' => $company) : $company)); } if (Arr::get($_GET, 'region')) { $query['region'] = strval($_GET['region']); } } if (Arr::get($_GET, 'fsam')) { $fsam = is_array($_GET['fsam']) ? array_map('strval', $_GET['fsam']) : explode(',', $_GET['fsam']); $query['data.13'] = count($fsam) == 1 ? array_shift($fsam) : array('$in' => $fsam); } $list = Database_Mongo::collection('jobs')->distinct('data.14', $query ?: NULL); sort($list); die(json_encode($list)); }
public function action_index() { if (!Group::current('allow_assign')) { throw new HTTP_Exception_403('Forbidden'); } $ids = array_keys(Arr::get($_POST, 'job', array())); if (!$ids) { Messages::save('Please, select at least one job!'); } else { $jobs = Database_Mongo::collection('jobs'); $result = $jobs->find(array('_id' => array('$in' => $ids))); $count = 0; foreach ($result as $job) { if (Arr::get($job, 'status') == Enums::STATUS_ARCHIVE || Arr::get($job, 'status') == Enums::STATUS_COMPLETE || Arr::get($job, 'status') == Enums::STATUS_PENDING) { if ($job['status'] == Enums::STATUS_PENDING) { $submissions = Database_Mongo::collection('submissions')->find(array('job_key' => $job['_id'], 'active' => 1))->count(); if ($submissions) { continue; } } $update = array('$set' => array('last_update' => time())); if (Arr::get($job, 'assigned')) { $update['$set']['status'] = Enums::STATUS_ALLOC; } else { $update['$unset']['status'] = 1; } $jobs->update(array('_id' => $job['_id']), $update); $count++; } } Messages::save($count . ' jobs were succesfully reset to initial state', 'success'); } $this->redirect('/search'); }
public function before() { parent::before(); if (!Group::current('is_admin')) { throw new HTTP_Exception_403('Forbidden'); } }
public function action_index() { if (!Group::current('allow_assign')) { throw new HTTP_Exception_403('Forbidden'); } $ids = array_keys(Arr::get($_POST, 'job', array())); if (!$ids) { Messages::save('Please, select at least one job!'); } else { $jobs = Database_Mongo::collection('jobs'); $submissions = Database_Mongo::collection('submissions')->distinct('job_key', array('job_key' => array('$in' => $ids), 'active' => 1)); $ids = array_values(array_diff($ids, $submissions)); $result = Database_Mongo::collection('jobs')->find(array('_id' => array('$in' => $ids))); print_r($result->explain()); $count = 0; foreach ($result as $job) { if (!in_array(Arr::get($job, 'status'), array(Enums::STATUS_ARCHIVE, Enums::STATUS_COMPLETE))) { $jobs->update(array('_id' => $job['_id']), array('$set' => array('last_update' => time(), 'status' => Enums::STATUS_COMPLETE))); $count++; } } Messages::save($count . ' jobs were succesfully completed', 'success'); } $this->redirect('/search'); }
public function before() { parent::before(); if (!Group::current('is_admin')) { throw new HTTP_Exception_403('Forbidden'); } ini_set('memory_limit', -1); }
public function action_delete() { if (!User::current('is_admin') && !Group::current('item_remove')) { throw new HTTP_Exception_403('Forbidden'); } $id = $this->request->param('id'); DB::delete('items')->where('id', '=', $id)->execute(); Messages::save('Item was successfully deleted!', 'info'); $this->redirect('/items'); }
public function action_index() { $items = DB::select(DB::expr('COUNT(*) as cnt'), DB::expr('COALESCE(`status`, "unattached") as status'))->from('unit_items')->join('tasks', 'left')->on('task_id', '=', 'tasks.id')->group_by('status'); if (!User::current('is_admin') && !Group::current('all_projects')) { $items->where('company_id', '=', User::current('company_id')); } $items = $items->execute()->as_array('status', 'cnt'); $view = View::factory('Dashboard')->bind('items', $items); $this->response->body($view); }
private function get_results($all = false) { $archive = Database_Mongo::collection('archive'); $filters = array(); if (Arr::get($_GET, 'action')) { if ($_GET['action'] == 2 && !Group::current('is_admin')) { $show = array_keys(Columns::get_visible()); $filters['fields'] = array('$in' => $show); } $filters['update_type'] = intval($_GET['action']); } if (Arr::get($_GET, 'ticket')) { $filters['job_key'] = $_GET['ticket']; } if (Arr::get($_GET, 'file')) { $filters['filename'] = $_GET['file']; } if (Arr::get($_GET, 'start')) { $start = strtotime($_GET['start']); $filters['update_time']['$gt'] = $start; } if (isset($filters['end'])) { $end = strtotime($_GET['end']); $filters['update_time']['$lt'] = $end; } $filters = $filters ? array(array('$match' => $filters)) : array(); $filters[] = array('$sort' => array('update_time' => -1, 'job_key' => 1)); if (!$all) { $count = Database_Mongo::collection('archive')->find(Arr::path($filters, '0.$match', array()))->count(); Pager::$count = $count; $filters[] = array('$skip' => Pager::offset()); $filters[] = array('$limit' => Pager::limit()); } $result = $archive->aggregateCursor($filters, array('allowDiskUse' => true)); $list = array(); $ids = array(); foreach ($result as $row) { $list[] = $row; $ids[$row['job_key']] = 1; } $result = Database_Mongo::collection('jobs')->find(array('_id' => array('$in' => array_keys($ids)))); $jobs = array(); foreach ($result as $job) { $jobs[$job['_id']] = Arr::get($job, 'data'); } $items = array(); foreach ($list as $row) { $row['data'] = array_intersect_key($row['data'], Columns::get_visible()); foreach (Columns::get_static() as $static => $show) { $row['static'][$static] = Arr::path($jobs, array($row['job_key'], $static)); } $items[] = $row; } return $items; }
public function action_index() { $id = $this->request->param('id'); $location = Arr::get($_GET, 'location', ''); $type = Arr::get($_GET, 'type', 'other'); $title = Arr::get($_GET, 'title', 'other'); $job = Database_Mongo::collection('jobs')->findOne(array('_id' => strval($id))); if (!$job) { throw new HTTP_Exception_404('Not found'); } if (!Group::current('show_all_jobs') && !in_array((int) User::current('company_id'), Arr::get($job, 'companies', array()), true) && !in_array((int) User::current('company_id'), Arr::get($job, 'ex', array()), true)) { throw new HTTP_Exception_403('Forbidden'); } switch ($type) { case 'photo-before': $type = 'Photos'; $filename = $id . '.' . Arr::path($job, 'data.9') . '.' . Arr::path($job, 'data.14') . '.before.%NUM%'; $title = ''; break; case 'photo-after': $type = 'Photos'; $filename = $id . '.' . Arr::path($job, 'data.9') . '.' . Arr::path($job, 'data.14') . '.after.%NUM%'; $title = ''; break; case 'jsa': $type = 'JSA-forms'; $filename = $id . '.' . Arr::path($job, 'data.9') . '.' . Arr::path($job, 'data.14') . '.JSA.%NUM%'; $title = ''; break; case 'waiver': $type = 'Waiver'; $filename = $id . '.' . Arr::path($job, 'data.9') . '.' . Arr::path($job, 'data.14') . '.Waiver.%NUM%'; $title = ''; break; case 'odtr': $title = ''; $type = 'otdr-traces'; $filename = ''; break; default: $type = 'Other'; $filename = ''; break; } $number = DB::select('numbering')->from('attachments')->where('job_id', '=', $id)->and_where('folder', '=', $type)->order_by('numbering', 'desc')->limit(1)->execute()->get('numbering'); $data = array('filename' => $filename, 'mime' => '', 'uploaded' => 0, 'user_id' => User::current('id'), 'job_id' => $id, 'folder' => $type, 'fda_id' => Arr::path($job, 'data.14'), 'address' => trim(preg_replace('/-{2,}/', '-', preg_replace('/[^0-9a-z\\-]/i', '-', Arr::path($job, 'data.8'))), '-'), 'title' => $title, 'numbering' => intval($number) + 1); $result = Arr::get(DB::insert('attachments', array_keys($data))->values(array_values($data))->execute(), 0); if (file_exists(DOCROOT . 'storage/' . $result)) { unlink(DOCROOT . 'storage/' . $result); } die(json_encode(array('success' => true, 'id' => $result))); }
public function action_financial() { if (!Group::current('is_admin') && !(Group::current('allow_finance') && Group::current('show_all_jobs'))) { throw new HTTP_Exception_403('Forbidden'); } $jobs = Database_Mongo::collection('jobs')->find(); foreach ($jobs as $job) { set_time_limit(30); Utils::calculate_financial($job); } header('Content-type: application/json'); die(json_encode(array('success' => true))); }
public function action_boms() { $id = intval($this->request->param('id')); if (User::current('is_admin') || Group::current('allow_assign')) { $result = DB::select('bom_items.id', 'code', 'bom_items.name', 'estimated', array('uoms.name', 'uom'))->from('bom_items')->join('unit_boms', 'left')->on('bom_id', '=', 'bom_items.id')->on('unit_id', '=', DB::expr($id))->on('task_id', '=', DB::expr(0))->join('uoms', 'left')->on('uom', '=', 'uoms.id')->order_by('name', 'asc')->execute()->as_array(); } else { $result = DB::select('bom_items.id', 'code', 'bom_items.name', DB::expr('0 as estimated'), array('uoms.name', 'uom'))->from('bom_items')->join('uoms', 'left')->on('uom', '=', 'uoms.id')->order_by('name', 'asc')->execute()->as_array(); } $items = array(); foreach ($result as $item) { $items[] = array('id' => intval($item['id']), 'code' => $item['code'], 'name' => $item['name'], 'avail' => floatval($item['estimated']), 'uom' => $item['uom'] ?: 'Unknown'); } header('Content-type: application/json'); die(json_encode($items)); }
/** * @param string $type * @param array $var * @param string $key * * @return string */ public static function editable($type, $var, $key, $filter = array('HTML', 'chars')) { $list = self::$types[$type]; if (!is_array($list)) { $list = array($list); } $values = array(); foreach ($list as $id) { $values[] = Arr::get($var, $id); } $value = call_user_func($filter, $var[$key]); if (User::current('is_admin') || Group::current('edit_data')) { return '<span class="editable" data-target="' . $type . '" data-ids="' . implode(',', $list) . '" data-values="' . implode(',', $values) . '" data-key="' . $key . '">' . ($value === '' ? '<i>not defined</i>' : $value) . '</span>'; } else { return $value === '' ? '<i>not defined</i>' : $value; } }
public function action_approve() { if (!Group::current('allow_assign')) { throw new HTTP_Exception_403('Forbidden'); } $id = Arr::get($_GET, 'id'); $submission = Database_Mongo::collection('submissions')->findOne(array('_id' => new MongoId($id))); if (!$submission || Arr::get($submission, 'active')) { throw new HTTP_Exception_404('Not found'); } $job = Database_Mongo::collection('jobs')->findOne(array('_id' => $submission['job_key'])); $value = Arr::get($job, $submission['key'], ''); $update_time = time(); if ($value != $submission['value']) { $archive = array('data' => array(substr($submission['key'], 5) => array('old_value' => $value, 'new_value' => $submission['value'])), 'fields' => substr($submission['key'], 5), 'job_key' => $job['_id'], 'user_id' => User::current('id'), 'update_time' => $update_time, 'update_type' => 2, 'filename' => 'MANUAL'); $update = array('$set' => array('last_update' => $update_time)); if ($submission['value']) { $update['$set'][$submission['key']] = $submission['value']; } else { $update['$unset'][$submission['key']] = 1; } if ($submission['key'] == 'data.44') { $status = preg_replace('/[^a-z]/', '', strtolower($submission['value'])); if ($status == 'built' && !Arr::path($job, 'data.264')) { $update['$set']['data.264'] = $update_time; } if ($status == 'tested' && !Arr::path($job, 'data.265')) { $update['$set']['data.265'] = $update_time; if (!Arr::path($job, 'data.264')) { $update['$set']['data.264'] = $update_time; } } } $company = intval(User::get($submission['user_id'], 'company_id')); $sub = array('$set' => array('admin_id' => User::current('id'), 'process_time' => $update_time, 'active' => -1)); $financial = floatval(DB::select('financial')->from('job_columns')->where('id', '=', substr($submission['key'], 5))->execute()->get('financial')); if ($financial && !in_array($company, Arr::get($job, 'companies', array()), true)) { $sub['$set']['financial_time'] = 0; } Database_Mongo::collection('archive')->insert($archive); Database_Mongo::collection('jobs')->update(array('_id' => $job['_id']), $update); Database_Mongo::collection('submissions')->update(array('_id' => new MongoId($id)), $sub); } die(json_encode(array('success' => true))); }
public function action_index() { if (!Group::current('allow_assign')) { throw new HTTP_Exception_403('Forbidden'); } $ids = array_keys(Arr::get($_POST, 'job', array())); if (!$ids) { Messages::save('Please, select at least one job!'); } else { $jobs = Database_Mongo::collection('jobs'); $result = $jobs->find(array('_id' => array('$in' => $ids))); $count = 0; foreach ($result as $job) { if (Arr::get($job, 'status') != Enums::STATUS_PENDING && Arr::get($job, 'status') != Enums::STATUS_ARCHIVE) { $jobs->update(array('_id' => $job['_id']), array('$set' => array('last_update' => time(), 'status' => Enums::STATUS_ARCHIVE))); $count++; } } Messages::save($count . ' jobs were succesfully archived', 'success'); } $this->redirect('/search'); }
/** * Generates a column sized form group * * <div class="row"> * <div class="col-sm-2">...</div> * </div> * * @param Group $group * * @return string */ public static function formColumnSizingTemplate($group) { $html = ''; if ($columnSizing = $group->get('columnSizing')) { $group->rewind(); while ($field = $group->current()) { $key = $group->key(); $class = $columnSizing[$key]; $element = Element::div(true); if ($class) { $element->addClass($class); } $html .= $element->toHtml($field->toHtml()); $group->next(); } $html = Element::div(true)->addClass('row')->toHtml($html); } else { $html = $group->html(); } return $html; }
public function action_remove() { if (!User::current('is_admin') && !Group::current('remove_attachments')) { throw new HTTP_Exception_403('Forbidden'); } $id = intval($this->request->param('id')); DB::delete('attachments')->where('id', '=', $id)->execute(); if (file_exists(DOCROOT . 'storage/' . $id)) { unlink(DOCROOT . 'storage/' . $id); } if (file_exists(DOCROOT . 'storage/' . $id . '.thumb')) { unlink(DOCROOT . 'storage/' . $id . '.thumb'); } header('Content-type: application/json'); die(json_encode(array('success' => true))); }
<a href="<?=URL::base()?>download/attachment/<?=$attachment?>"><img src="<?=URL::base()?>download/thumb/<?=$attachment?>" /></a> <?php endforeach; if ($i > 2) echo '</div>';?> </td> <?php endif;?> </tr> <?php endforeach; else:?> <tr> <td colspan="<?=count($columns) + ($geo ? 2 : 1)?>"><h4 class="text-danger">No records found!</h4></td> </tr> <?php endif;?> </table> </div> </div> <?php if (Group::current('is_admin')):?> <button type="button" class="btn btn-danger pull-right" id="reports-remove"><span class="glyphicon glyphicon-remove"></span> Remove</button> <?php endif;?> <div class="btn-group pull-right"> <button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <span class="glyphicon glyphicon-export"></span> Export options <span class="caret"></span> </button> <ul class="dropdown-menu"> <li><a href="?id=<?=$_GET['id']?>&export" class="add-items-to-request"><span class="glyphicon glyphicon-list-alt">Export to CSV</span></a></li> <li><a href="?id=<?=$_GET['id']?>&export=excel" class="add-items-to-request"><span class="glyphicon glyphicon-file">Export to Excel</span></a></li> <li><a href="?id=<?=$_GET['id']?>&export&all"><span class="glyphicon glyphicon-list-alt">Export all to CSV</span></a></li> <li><a href="?id=<?=$_GET['id']?>&export=excel&all"><span class="glyphicon glyphicon-file">Export all to Excel</span></a></li> </ul> </div> <?php endif;?>
public function action_index() { if (!Group::current('allow_reports')) { throw new HTTP_Exception_403('Forbidden'); } $regions = DB::select('id', 'name')->from('regions')->execute()->as_array('id', 'name'); $groups = DB::select('id', 'name')->from('groups')->execute()->as_array('id', 'name'); $form = new Form(); $form->add('region', 'Region', Form::SELECT, array('' => 'Please, select region') + $regions, array('not_empty')); if (isset($_POST['group']) && isset($_POST['csv'])) { if (isset($_POST['job'])) { $query = array('_id' => array('$in' => array_keys($_POST['job']))); $region = array('name' => 'PARTIAL'); } else { if (!Arr::get($_POST, 'region')) { throw new HTTP_Exception_404('Not found'); } $region = DB::select('id', 'name')->from('regions')->where('id', '=', $_POST['region'])->execute()->current(); $query = array('region' => $region['id']); } $jobs = Database_Mongo::collection('jobs')->find($query); $columns = array(); $csv = $_POST['csv']; if ($_POST['group']) { if (Group::get($_POST['group'], 'is_admin')) { $result = DB::select('id')->from('job_columns')->execute()->as_array(NULL, 'id'); } else { $result = DB::select('column_id')->from('group_columns')->where('group_id', '=', $_POST['group'])->and_where('permissions', '>', 0)->execute()->as_array(NULL, 'column_id'); } if ($csv != 'none') { foreach ($result as $column) { if ($csv == 'all' || !($csv == 'csv' xor Columns::get_csv($column))) { $columns[$column] = Columns::get_name($column); } } } } else { foreach (Arr::get($_POST, 'columns', array()) as $column => $value) { $columns[$column] = Columns::get_name($column); } } header("Content-type: text/csv"); header('Content-disposition: filename="' . date('Ymd') . '_EXEL_' . $region['name'] . '_EOD.csv"'); $file = tmpfile(); fputcsv($file, array(0 => 'Ticket Of Work') + $columns); while ($job = $jobs->next()) { $data[0] = $job['_id']; $i = 1; foreach ($columns as $key => $value) { $data[$i++] = iconv("CP1251", 'CP1251//ignore', Columns::output(Arr::get($job['data'], $key, ''), Columns::get_type($key), true)); } fputcsv($file, $data); } rewind($file); fpassthru($file); fclose($file); die; } $view = View::factory('Jobs/Export')->bind('regions', $regions)->bind('groups', $groups); $this->response->body($view); }
public function action_index() { if (!Group::current('allow_assign')) { throw new HTTP_Exception_403('Forbidden'); } $ids = array_keys(Arr::get($_POST, 'job', array())); $type = intval(Arr::get($_POST, 'type')); $company = intval(Arr::get($_POST, 'company')); if (!$ids) { Messages::save('Please, select at least one job!'); } elseif (!$type) { Messages::save('Please, select works type!'); } elseif (!$company) { Messages::save('Please, select company!'); } elseif (DB::select('id')->from('job_types')->where('id', '=', $type)->execute()->get('id') && ($company == -1 || DB::select('id')->from('companies')->where('id', '=', $company)->execute()->get('id'))) { $assign_time = time(); $jobs = Database_Mongo::collection('jobs'); $result = $jobs->find(array('_id' => array('$in' => $ids))); $count = 0; $values = array(); $users = array(); while ($job = $result->next()) { if (Arr::path($job, 'assigned.' . $type) != $company) { $update = array(); if (Arr::path($job, 'assigned.' . $type)) { $users = DB::select('id')->from('users')->where('company_id', '=', $job['assigned'][$type])->execute()->as_array(NULL, 'id'); $subs = Database_Mongo::collection('submissions')->findOne(array('job_key' => $job['_id'], 'active' => 1, 'user_id' => array('$in' => $users))); if ($subs) { continue; } else { $subs = Database_Mongo::collection('submissions')->find(array('job_key' => $job['_id'], 'active' => -1))->sort(array('process_time' => 1)); $list = array(); foreach ($subs as $sub) { $list[$sub['key']] = $sub['_id']; } $financial = DB::select('id')->from('job_columns')->where('financial', '>', 0)->execute()->as_array(NULL, 'id'); $res = array(); foreach ($financial as $column) { if (isset($list['data.' . $column])) { $res[$column] = $list['data.' . $column]; } } Database_Mongo::collection('submissions')->update(array('_id' => array('$in' => array_values($res))), array('$set' => array('financial_time' => 0)), array('multiple' => 1)); if (!in_array($job['assigned'][$type], Arr::get($job, 'ex', array()), true)) { $job['ex'][] = intval($job['assigned'][$type]); $update['$set']['ex'] = $job['ex']; } } } if ($company == -1) { unset($job['assigned'][$type]); } else { $job['assigned'][$type] = $company; $update['$set']['data.266'] = $assign_time; } if (Arr::get($job, 'assigned')) { $update['$set']['assigned'] = $job['assigned']; } else { $update['$unset']['assigned'] = 1; } $update['$set']['last_update'] = $assign_time; $companies = array(); if (Arr::get($job, 'assigned')) { foreach ($job['assigned'] as $cmp) { if ($cmp) { $companies[$cmp] = 1; } } } $update['$set']['companies'] = array_keys($companies); $status = Arr::get($job, 'status', Enums::STATUS_UNALLOC); if (in_array($status, array(Enums::STATUS_UNALLOC, Enums::STATUS_COMPLETE, Enums::STATUS_ARCHIVE))) { if ($companies) { $update['$set']['status'] = Enums::STATUS_ALLOC; } } elseif ($status == Enums::STATUS_ALLOC) { if (!$companies) { $update['$unset']['status'] = 1; } } else { $update['$set']['status'] = Enums::STATUS_COMPLETE; } $count++; $jobs->update(array('_id' => $job['_id']), $update); $values[] = array('time' => $assign_time, 'user_id' => User::current('id'), 'company_id' => max($company, 0), 'job_id' => $job['_id'], 'type' => $type); } } if ($values) { $insert = DB::insert('assign_log', array_keys($values[0])); foreach ($values as $value) { $insert->values($value); } $insert->execute(); } if ($company == -1) { Messages::save($count . ' jobs were succesfully unassigned', 'success'); } else { Messages::save($count . ' jobs were succesfully assigned to ' . Company::get($company, 'name'), 'success'); $users = DB::select('id')->from('users')->where('company_id', '=', $company)->execute()->as_array(NULL, 'id'); $message = $count . ' tickets were allocated on ' . date('d-m-Y H:i', $assign_time) . '. <a href="javascript:;" class="tickets-search-assign" data-date="' . date('d-m-Y H:i:s', $assign_time) . '">View ticket(s)</a>'; $insert = DB::insert('notifications', array('user_id', 'message')); foreach ($users as $user) { $insert->values(array($user, $message)); } $insert->execute(); } } $this->redirect('/search'); }
public function action_index() { $id = intval($this->request->param('id')); $attachment = DB::select()->from('attachments')->where('id', '=', $id)->execute()->current(); if (!$attachment) { throw new HTTP_Exception_404('Not found'); } if (Arr::get($attachment, 'uploaded')) { throw new HTTP_Exception_403('Forbidden'); } $job_id = Arr::get($attachment, 'job_id'); $job = Database_Mongo::collection('jobs')->findOne(array('_id' => strval($job_id))); if (!$job) { throw new HTTP_Exception_404('Not found'); } if (!Group::current('show_all_jobs') && !in_array((int) User::current('company_id'), Arr::get($job, 'companies', array()), true) && !in_array((int) User::current('company_id'), Arr::get($job, 'ex', array()), true)) { throw new HTTP_Exception_403('Forbidden'); } if ($_FILES) { try { $file = Arr::get($_FILES, 'attachment', array()); $file['name'] = trim(preg_replace('/-{2,}/', '-', preg_replace('/[^0-9a-z\\-\\.]/i', '-', Arr::get($file, 'name', ''))), '-'); preg_match_all("/([0-9]+)/", Arr::get($_SERVER, 'HTTP_CONTENT_RANGE', ''), $matches); $range = Arr::get($matches, 0); $size = Arr::get($range, 2, filesize($file['tmp_name'])); if (!is_uploaded_file($file['tmp_name'])) { die(json_encode(array('attachment' => array('name' => $file['name'], 'size' => $size, 'error' => 'Error!')))); } $src = fopen($file['tmp_name'], 'r'); $dest = fopen(DOCROOT . 'storage/' . $id, 'c'); fseek($dest, Arr::get($range, 0, 0)); $buf = fread($src, $size); fwrite($dest, $buf); fclose($dest); fclose($src); unlink($file['tmp_name']); if (!$range || Arr::get($range, 1) + 1 == Arr::get($range, 2)) { $data = array('filename' => $file['name'], 'mime' => $file['type'], 'uploaded' => time()); if ($attachment['filename']) { $data['filename'] = $attachment['filename']; $pos = strrpos($file['name'], '.'); if ($pos !== false) { $data['filename'] .= substr($file['name'], $pos); } } else { $data['filename'] = ($attachment['folder'] == 'Other' ? $attachment['title'] : '') . $file['name']; } $data['filename'] = str_replace('%NUM%', $attachment['numbering'], $data['filename']); Database::instance()->begin(); DB::update('attachments')->set($data)->where('id', '=', $id)->execute(); $filename = $data['filename']; $data = array('user_id' => User::current('id'), 'job_id' => $attachment['job_id'], 'uploaded' => $data['uploaded'], 'location' => $attachment['location'], 'filename' => $attachment['folder'] . ' / ' . $attachment['fda_id'] . ' / ' . $attachment['address'] . ' / ' . $data['filename'], 'action' => 1); DB::insert('upload_log', array_keys($data))->values(array_values($data))->execute(); Database::instance()->commit(); Database_Mongo::collection('jobs')->update(array('_id' => $attachment['job_id']), array('$unset' => array('downloaded' => 1), '$set' => array('last_update' => time()))); Messages::save("File " . $file['name'] . ' was successfully uploaded!', 'success'); $is_image = preg_match('/^image\\/.*$/i', $file['type']); die(json_encode(array('attachment' => array('name' => $file['name'], 'size' => $size, 'content' => '<table><tr>' . (Group::current('allow_assign') ? '<td><a href="' . URL::base() . 'search/view/' . $id . '?delete=' . $id . '" confirm="Do you really want to delete this attachment? This action can\'t be undone!!!" class="text-danger glyphicon glyphicon-remove remove-link"></a></td>' : '') . '<td><div class="td-image-center">' . ($is_image ? '<img src="' . URL::base() . 'download/thumb/' . $id . '" alt="Thumbnail" />' : '<img src="http://stdicon.com/' . $file['type'] . '?size=96&default=http://stdicon.com/text" />') . '</div></td><td><a data-id="' . $id . '" class="' . ($is_image && $attachment['folder'] != 'Signatures' ? 'image-attachments' : '') . '" href="' . URL::base() . 'download/attachment/' . $id . '">' . HTML::chars($attachment['folder']) . '<br/>' . HTML::chars($attachment['fda_id']) . '<br/>' . HTML::chars($attachment['address']) . '<br/>' . HTML::chars($filename) . '</a><br/> - Uploaded ' . date('d-m-Y H:i', $data['uploaded']) . ' by ' . User::current('login') . '</td></tr></table>', 'message' => Messages::render())))); } } catch (Exception $e) { die($e->getMessage()); } die(json_encode(array('attachment' => array('name' => $file['name'], 'size' => $size)))); } $view = View::factory("Jobs/UploadFile"); $this->response->body($view); }
<?php endif; ?> <?php if (Group::current('is_admin') || (Group::current('allow_finance') && Group::current('show_all_jobs'))): ?> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Tools <span class="caret"></span></a> <ul class="dropdown-menu"> <?php if (Group::current('is_admin')): ?> <li><a class="tools" href="<?= URL::base() ?>tools/discrepancies">Fix discrepancies</a> </li> <li><a class="tools" href="<?= URL::base() ?>tools/underbore">Fix underbore</a></li> <?php endif; ?> <li><a class="tools" href="<?= URL::base() ?>tools/financial">Fix financial values</a></li> </ul> </li> <?php endif; ?> <?php if (Group::current('allow_assign')): ?> <li class="<?= Request::current()->directory() == '' && Request::current()->controller() == 'Attachments' ? 'active' : '' ?>"> <a href="<?= URL::base() ?>attachments">Attachments</a></li> <?php endif; ?> <li class="divider"></li> </ul> <ul class="nav navbar-nav navbar-right"> <li> <a href="javascript:;"><?= User::current('login') . (User::current('company_id') ? ' (' . Company::current('name') . ')' : '') ?></a> </li> <li><a href="<?= URL::base() ?>login/deauth">Log out</a></li> </ul> </div> </div> </nav> <div class="container col-xs-12">
<th class="sortable" data-id="submission">Submission date</th> <th class="sortable" data-id="approval">Approval date</th> <th>User</th> <?php if (Group::current('allow_assign')):?><th>Company</th><?php endif;?> <th>Column</th> <th>Value</th> </tr> <?php foreach ($submissions as $job => $list):?> <tr class="text-center"> <th colspan="<?=(Group::current('allow_assign')) ? 6 : 5?>"> <a href="<?=URL::base()?>search/view/<?=$job?>"><?=$job?>, <?=Arr::path($jobs, array($job, 'l'))?>, <?=Arr::path($jobs, array($job, 'f'))?>, <?=Arr::path($jobs, array($job, 'a'))?></a> </th> </tr> <?php foreach ($list as $submission): $key = substr($submission['key'], 5); $status = Arr::get($submission, 'active', 0);?> <tr class="text-center <?=$status > 0 ? 'yellow' : ($status < 0 ? 'lgreen' : 'rose')?>"> <td><?=date('d-m-Y H:i', $submission['update_time'])?></td> <td><?=isset($submission['process_time']) ? date('d-m-Y H:i', $submission['process_time']) : ''?></td> <td><?=User::get($submission['user_id'], 'login')?></td> <?php if (Group::current('allow_assign')):?><td><?=Arr::get($companies, User::get($submission['user_id'], 'company_id'), 'Unknown')?></td><?php endif;?> <td><?=Columns::get_name($key)?></td> <td class="<?=strlen(Columns::output($submission['value'], Columns::get_type($key))) > 2 ? 'shorten' : ''?>"><?=Columns::output($submission['value'], Columns::get_type($key))?></td> </tr> <?php endforeach;?> <?php endforeach;?> </table> <div class="upload-buttons text-right"> <a href="?export&company=<?=Arr::get($_GET, 'company')?>&start=<?=Arr::get($_GET, 'start', date('d-m-Y', $week))?>&end=<?=Arr::get($_GET, 'end', date('d-m-Y'))?>" class="btn btn-info"><span class="glyphicon glyphicon-export"></span> Export</a> <a href="?export2&company=<?=Arr::get($_GET, 'company')?>&start=<?=Arr::get($_GET, 'start', date('d-m-Y', $week))?>&end=<?=Arr::get($_GET, 'end', date('d-m-Y'))?>" class="btn btn-primary"><span class="glyphicon glyphicon-export"></span> Export grouped</a> <a href="?export3&company=<?=Arr::get($_GET, 'company')?>&start=<?=Arr::get($_GET, 'start', date('d-m-Y', $week))?>&end=<?=Arr::get($_GET, 'end', date('d-m-Y'))?>" class="btn btn-warning"><span class="glyphicon glyphicon-export"></span> Export all columns</a> </div>
public function action_unattached() { $query = array('type' => Form::FORM_TYPE_COMMON); $forms = array(); $result = Database_Mongo::collection('forms')->find($query, array('name' => 1)); foreach ($result as $form) { $forms[strval($form['_id'])] = $form['name']; } if (Group::current('show_all_jobs')) { if (isset($_GET['company'])) { $company = is_array($_GET['company']) ? $_GET['company'] : explode(',', $_GET['company']); $query['company'] = array('$in' => array_map('intval', $company)); } } else { $query['company'] = array('$in' => array(User::current('company_id'))); } $result = Database_Mongo::collection('forms-data')->find($query, array('data' => 0))->sort(array('last_update' => -1)); $companies = array(); $list = array(); foreach ($result as $form) { $companies[$form['company']] = 1; $list[] = $form; } if ($companies) { $companies = DB::select('id', 'name')->from('companies')->where('id', 'IN', array_keys($companies))->execute()->as_array('id', 'name'); } $files = DB::select()->from('attachments')->where('fda_id', '=', 'Unattached')->order_by('uploaded', 'DESC'); if (isset($query['company'])) { $files->and_where('user_id', 'IN', DB::select('id')->from('users')->where('company_id', 'IN', $query['company']['$in'])); } $files = $files->execute()->as_array(); $view = View::factory('Forms/Unattached')->bind('forms', $forms)->bind('companies', $companies)->bind('list', $list)->bind('files', $files); $this->response->body($view); }
public function action_index() { $start = Arr::get($_GET, 'start') ? strtotime($_GET['start']) : strtotime('this week', strtotime('this week') > time() ? strtotime('yesterday') : time()); $end = Arr::get($_GET, 'end') ? strtotime($_GET['end']) + 86399 : time(); $query = array('update_time' => array('$gt' => intval($start), '$lt' => intval($end))); if (Arr::get($_GET, 'app-start')) { $query['process_time']['$gt'] = strtotime($_GET['app-start']); } if (Arr::get($_GET, 'app-end')) { $query['process_time']['$lt'] = strtotime($_GET['app-end']) + 86399; } if (Group::current('allow_assign')) { $companies = DB::select('id', 'name')->from('companies')->order_by('name', 'asc')->execute()->as_array('id', 'name'); } if (!Group::current('allow_assign') || Arr::get($_GET, 'company')) { $query['user_id'] = array('$in' => DB::select('id')->from('users')->where('company_id', '=', Group::current('allow_assign') ? $_GET['company'] : User::current('company_id'))->execute()->as_array(NULL, 'id')); } $jobs = array(); if (Arr::get($_GET, 'finished')) { $jobs['data.245'] = $_GET['finished']; } if (Arr::get($_GET, 'ticket')) { $tickets = explode(',', $_GET['ticket']); $q = array(); foreach ($tickets as $ticket) { $ticket = preg_replace('/[^a-z0-9]/i', '', strval($ticket)); if (!$ticket) { continue; } if (preg_match('/^T1W[0-9]{12}$/', $ticket)) { $q[] = $ticket; } else { $q[] = new MongoRegex('/.*' . $ticket . '.*/i'); } } if (count($q) > 1) { $jobs['_id'] = array('$in' => $q); } elseif ($q) { $jobs['_id'] = $q[0]; } } if (Arr::get($_GET, 'fsa')) { $values = is_array($_GET['fsa']) ? $_GET['fsa'] : explode(',', $_GET['fsa']); $jobs['data.12'] = count($values) > 1 ? array('$in' => array_values($values)) : current($values); } if (Arr::get($_GET, 'fsam')) { $values = is_array($_GET['fsam']) ? $_GET['fsam'] : explode(',', $_GET['fsam']); $jobs['data.13'] = count($values) > 1 ? array('$in' => array_values($values)) : current($values); } if (Arr::get($_GET, 'fda')) { $values = is_array($_GET['fda']) ? $_GET['fda'] : explode(',', $_GET['fda']); $jobs['data.14'] = count($values) > 1 ? array('$in' => array_values($values)) : current($values); } if (Arr::get($_GET, 'address')) { $jobs['data.8'] = new MongoRegex('/.*' . strval($_GET['address']) . '.*/mi'); } if ($jobs) { if (count($jobs) == 1 && isset($jobs['_id'])) { $query['job_key'] = $jobs['_id']; } else { $query['job_key'] = array('$in' => Database_Mongo::collection('jobs')->distinct('_id', $jobs)); } } $sort = array('job_key' => 1); if (!Arr::get($_GET, 'sort')) { $_GET['sort'] = array('-submission'); } foreach ($_GET['sort'] as $s) { $dir = substr($s, 0, 1) == '-' ? -1 : 1; $s = substr($s, 1); switch ($s) { case 'submission': $sort['update_time'] = $dir; break; case 'approval': $sort['process_time'] = $dir; break; } } $result = Database_Mongo::collection('submissions')->find($query)->sort($sort); $submissions = array(); $users = array(); foreach ($result as $submission) { $submissions[$submission['job_key']][] = $submission; $users[$submission['user_id']] = 1; } if ($users) { User::get(array_keys($users)); } if (isset($_GET['export'])) { header('Content-type: text/csv'); header('Content-disposition: filename="Submissions.' . date('Ymd', $start) . '-' . date('Ymd', $end) . '.' . date('YmdHi', time()) . '.csv"'); $file = tmpfile(); $headers = array('Tickets ID', 'FDA ID', 'LOC ID', 'Address', 'Submission Date', 'Approval Date', 'User'); if (Group::current('allow_assign')) { $headers[] = 'Company'; } $headers[] = 'Column'; $headers[] = 'Value'; fputcsv($file, $headers); $result = Database_Mongo::collection('jobs')->find(array('_id' => array('$in' => array_keys($submissions))), array('data.8' => 1, 'data.9' => 1, 'data.14' => 1)); $jobs = array(); foreach ($result as $job) { $jobs[$job['_id']] = array('a' => Arr::path($job, 'data.8', ''), 'f' => Arr::path($job, 'data.14', ''), 'l' => Arr::path($job, 'data.9', '')); } foreach ($submissions as $job => $list) { foreach ($list as $submission) { $key = substr($submission['key'], 5); $data = array($job, Arr::path($jobs, array($job, 'f')), Arr::path($jobs, array($job, 'l')), Arr::path($jobs, array($job, 'a')), date('d-m-Y H:i', $submission['update_time']), Arr::get($submission, 'process_time') ? date('d-m-Y H:i', $submission['process_time']) : '', User::get($submission['user_id'], 'login')); if (Group::current('allow_assign')) { $data[] = Arr::get($companies, User::get($submission['user_id'], 'company_id'), 'Unknown'); } $data[] = Columns::get_name($key); $data[] = Columns::output($submission['value'], Columns::get_type($key), true); fputcsv($file, $data); } } fseek($file, 0); fpassthru($file); fclose($file); die; } elseif (isset($_GET['export2'])) { //header('Content-type: text/plain'); header('Content-type: text/csv'); header('Content-disposition: filename="Submissions.' . date('Ymd', $start) . '-' . date('Ymd', $end) . '.' . date('YmdHi', time()) . '.csv"'); $result = array(); $columns = array(); foreach ($submissions as $job => $list) { foreach ($list as $submission) { $key = substr($submission['key'], 5); $result[$job][$submission['update_time']][$submission['user_id']][$key] = $submission['value']; $columns[$key] = Columns::get_name($key); } } $submissions = $result; ksort($columns); $headers = array('Tickets ID', 'FDA ID', 'LOC ID', 'Address', 'Submission Date', 'User'); if (Group::current('allow_assign')) { $headers[] = 'Company'; } /*$columns = Columns::get_visible();*/ foreach ($columns as $column) { $headers[] = $column; } $columns = array_keys($columns); $result = Database_Mongo::collection('jobs')->find(array('_id' => array('$in' => array_keys($submissions))), array('data.8' => 1, 'data.9' => 1, 'data.14' => 1)); $jobs = array(); foreach ($result as $job) { $jobs[$job['_id']] = array('f' => Arr::path($job, 'data.14', ''), 'l' => Arr::path($job, 'data.9', ''), 'a' => Arr::path($job, 'data.8', '')); } $file = tmpfile(); fputcsv($file, $headers); foreach ($submissions as $job => $list) { foreach ($list as $time => $values) { foreach ($values as $user => $submission) { $row = array($job, Arr::path($jobs, $job . '.f'), Arr::path($jobs, $job . '.l'), Arr::path($jobs, $job . '.a'), date('d-m-Y H:i', $time), User::get($user, 'login')); if (Group::current('allow_assign')) { $row[] = Arr::get($companies, User::get($user, 'company_id')); } foreach ($columns as $column) { $row[] = Columns::output(Arr::get($submission, $column, ''), Columns::get_type($column), true); } fputcsv($file, $row); } } } fseek($file, 0); fpassthru($file); fclose($file); //print_r($result); die; } elseif (isset($_GET['export3'])) { //header('Content-type: text/plain'); header('Content-type: text/csv'); header('Content-disposition: filename="Submissions.' . date('Ymd', $start) . '-' . date('Ymd', $end) . '.' . date('YmdHi', time()) . '.csv"'); $result = array(); foreach ($submissions as $job => $list) { foreach ($list as $submission) { $key = substr($submission['key'], 5); $result[$job][$submission['update_time']][$submission['user_id']][$key] = $submission['value']; } } $submissions = $result; $headers = array('Tickets ID', 'FDA ID', 'LOC ID', 'Address', 'Submission Date', 'User'); if (Group::current('allow_assign')) { $headers[] = 'Company'; } $columns = Columns::get_visible(); foreach ($columns as $column) { $headers[] = $column; } $columns = array_keys($columns); $result = Database_Mongo::collection('jobs')->find(array('_id' => array('$in' => array_keys($submissions))), array('data.8' => 1, 'data.9' => 1, 'data.14' => 1)); $jobs = array(); foreach ($result as $job) { $jobs[$job['_id']] = array('f' => Arr::path($job, 'data.14', ''), 'l' => Arr::path($job, 'data.9', ''), 'a' => Arr::path($job, 'data.8', '')); } $file = tmpfile(); fputcsv($file, $headers); foreach ($submissions as $job => $list) { foreach ($list as $time => $values) { foreach ($values as $user => $submission) { $row = array($job, Arr::path($jobs, $job . '.f'), Arr::path($jobs, $job . '.l'), Arr::path($jobs, $job . '.a'), date('d-m-Y H:i', $time), User::get($user, 'login')); if (Group::current('allow_assign')) { $row[] = Arr::get($companies, User::get($user, 'company_id')); } foreach ($columns as $column) { $row[] = Arr::get($submission, $column) ? Columns::output($submission[$column], Columns::get_type($column), true) : ''; } fputcsv($file, $row); } } } fseek($file, 0); fpassthru($file); fclose($file); //print_r($result); die; } $result = Database_Mongo::collection('jobs')->find(array('_id' => array('$in' => array_keys($submissions))), array('data.8' => 1, 'data.9' => 1, 'data.14' => 1)); $jobs = array(); foreach ($result as $job) { $jobs[$job['_id']] = array('f' => Arr::path($job, 'data.14', ''), 'l' => Arr::path($job, 'data.9', ''), 'a' => Arr::path($job, 'data.8', '')); } $view = View::factory("Reports/Submissions")->bind('companies', $companies)->bind('submissions', $submissions)->bind('jobs', $jobs); $this->response->body($view); }
<div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="myModalLabel">Modify filters</h4> </div> <div class="modal-body" id="filter-form" style="min-height: 300px;"> <div class="col-xs-2"> <label class="control-label">Region: </label> </div> <div class="col-xs-3"> <?=Form::select('region', array('' => 'All regions') + $regions, Arr::get($_GET, 'region'), array('class' => 'form-control region-filter multiselect'))?> </div> <div class="clearfix"> </div> <?php if (Group::current('show_all_jobs')):?> <div class="col-xs-2"> <label class="control-label">Contractor: </label> </div> <div class="col-xs-3"> <?=Form::select('company[]', $companies, isset($_GET['company']) ? $_GET['company'] : [], array('class' => 'multiselect form-control company-filter', 'multiple'=>'multiple'))?> </div> <div class="clearfix"> </div> <?php endif;?> <div class="col-xs-2 fsa-fsam-hidden"> <label class="control-label">FSA: </label> </div> <div class="col-xs-3 fsa-fsam-hidden"> <?=Form::select('fsa[]', $fsa, NULL, array('class' => 'fsa-filter multiselect', 'multiple' => 'multiple'))?> </div>