Пример #1
0
 public function testSet()
 {
     $columns = new Columns();
     $actual = $columns->set(['first', 'second', 'third' => 'MD5(data)']);
     $this->assertSame($columns, $actual);
     $expected = 'first, second, MD5(data) AS third';
     $this->assertEquals($expected, (string) $columns);
 }
Пример #2
0
 /**
  * @param int    $index     The position of the column in the index (0 indexed)
  * @param Column $column
  *
  * @return Index
  * @throws Exception\Manager
  */
 public function addColumn($index, Column $column)
 {
     if ($this->columns->offsetExists($index) === true) {
         throw Exception\Index::columnAlreadyExists($index, $this->getName());
     }
     $this->columns->offsetSet($index, $column);
     return $this;
 }
Пример #3
0
 /**
  * Add a foreign column for the relation
  *
  * @param Column $column
  *
  * @return $this
  * @throws Exception\Manager
  */
 public function addForeignForeignColumn(Column $column)
 {
     $alias = $this->normalizeName($column->getName());
     if ($this->foreignForeignColumns->offsetExists($alias) === true) {
         throw Exception\Relation::foreignForeignColumnAlreadyExists($alias, $this->getName());
     }
     $this->foreignForeignColumns->offsetSet($alias, $column);
     return $this;
 }
Пример #4
0
 private static function init()
 {
     $columns = DB::select()->from('job_columns')->execute()->as_array();
     $result = DB::select('column_id', 'permissions', 'search')->from('group_columns')->where('group_id', '=', Group::current('id'))->execute();
     $permissions = $result->as_array('column_id', 'permissions');
     $search = $result->as_array('column_id', 'search');
     foreach ($columns as $column) {
         self::$all[$column['id']] = $column['name'];
         self::$types[$column['id']] = $column['type'];
         self::$tabs[$column['id']] = $column['tab_id'];
         if ($column['csv']) {
             self::$csv[$column['id']] = $column['name'];
         }
         if ($column['direct']) {
             self::$direct[$column['id']] = $column['name'];
         }
         if ($column['show_reports']) {
             self::$static[$column['id']] = $column['show_reports'];
         }
         if (Arr::get($permissions, $column['id'])) {
             self::$permissions[$column['id']] = Arr::get($permissions, $column['id']);
         }
         if (Arr::get($search, $column['id'])) {
             self::$search[$column['id']] = Arr::get($search, $column['id']);
         }
         if ($column['track']) {
             self::$track[$column['id']] = $column['id'];
         }
         if ($column['persistent']) {
             self::$persistent[$column['id']] = $column['id'];
         }
         if ($column['read_only']) {
             self::$readonly[$column['id']] = $column['id'];
         }
         if (floatval($column['financial'])) {
             self::$financial[$column['id']] = floatval($column['financial']);
         }
     }
     if (Group::current('is_admin')) {
         self::$columns = self::$all;
         self::$search = self::$static;
     } else {
         self::$columns = array_intersect_key(self::$all, self::$permissions);
     }
 }
Пример #5
0
 public function action_indexes()
 {
     $columns = DB::select('column_id')->distinct(true)->from('group_columns')->where('search', '=', 2)->execute()->as_array(NULL, 'column_id');
     foreach ($columns as $column) {
         $index = array();
         $type = Columns::get_type($column);
         $name = 'data.' . $column;
         switch ($type) {
             case 'text':
                 //$index[$name] = 'text';
                 break;
             default:
                 $index[$name] = true;
         }
         if ($index) {
             Database_Mongo::collection('jobs')->ensureIndex($index, array('sparse' => true));
         }
     }
     die('Done');
 }
Пример #6
0
 public function action_search()
 {
     $id = Arr::get($_GET, 'id');
     if (!DB::select('id')->from('job_columns')->where('id', '=', $id)->execute()->get('id')) {
         throw new HTTP_Exception_403();
     }
     $group = Arr::get($_GET, 'group');
     if (!Group::get($group)) {
         throw new HTTP_Exception_403();
     }
     $state = intval(Arr::get($_GET, 'state'));
     DB::query(Database::INSERT, DB::expr("INSERT INTO `group_columns` (`group_id`, `column_id`, `search`) VALUES (:group, :id, :state) ON DUPLICATE KEY UPDATE `search` = :state", array(':group' => $group, ':id' => $id, ':state' => $state))->compile())->execute();
     if ($state == 2) {
         if (Columns::get_type($id) != 'text') {
             Database_Mongo::collection('jobs')->ensureIndex(array('data.' . $id => true), array('sparse' => true));
         }
     } else {
         if (!DB::select('group_id')->from('group_columns')->where('column_id', '=', $id)->and_where('search', '=', 2)->execute()->get('group_id')) {
             Database_Mongo::collection('jobs')->deleteIndex(array('data.' . $id => true));
         }
     }
     die(json_encode(array('success' => true)));
 }
Пример #7
0
</div>
<div class="wrapper">
  <a href="" title="">
  <div class="logo" style="background:url() no-repeat left;height: 120px"></div>
  </a>
</div>
<div class="navbar navbar-primary" role="navigation">
  <div class="wrapper">
    <div class="navbar-collapse collapse">
        <ul class="nav navbar-nav">
            <li><?php 
echo CHtml::link('首页', zmf::config('baseurl'));
?>
</li>
            <?php 
$topcols = Columns::navbar();
foreach ($topcols as $col) {
    ?>
            <li class="<?php 
    echo $col['active'] ? 'active' : '';
    ?>
"><?php 
    echo CHtml::link($col['title'], $col['url']);
    ?>
</li>
            <?php 
}
?>
          
        </ul>        
    </div><!--/.nav-collapse -->
Пример #8
0
 public function action_export()
 {
     $id = $this->request->param('id');
     if ($id == 'all') {
         ini_set('memory_limit', '4G');
     }
     $result = $this->get_results($id == 'all');
     $reports = array();
     foreach (Columns::get_static() as $column => $value) {
         $reports[$column] = Columns::get_name($column);
     }
     $file = tmpfile();
     $actions = array('1' => 'Created', '2' => 'Updated', '3' => 'Removed');
     $data = array('Ticket ID', 'Date', 'Action', 'File name');
     foreach ($reports as $id => $name) {
         $data[] = $name;
     }
     $data[] = "Column name";
     $data[] = "Old value";
     $data[] = "New value";
     fputcsv($file, $data);
     foreach ($result as $ticket) {
         $ticket['update_time'] = date('d-m-Y H:i', $ticket['update_time']);
         $ticket['type'] = Arr::get($actions, $ticket['update_type'], 'Unknown');
         $data = array($ticket['job_key'], $ticket['update_time'], $ticket['type'], $ticket['filename']);
         foreach ($reports as $id => $name) {
             $data[] = Columns::output(Arr::path($ticket, 'static.' . $id), Columns::get_type($id), true);
         }
         if ($ticket['update_type'] == 2) {
             if ($ticket['data']) {
                 $base = $data;
                 foreach ($ticket['data'] as $key => $value) {
                     $data = $base;
                     $date = Columns::get_type($key) == 'date';
                     $data[] = Columns::get_name($key);
                     $data[] = $date && $value['old_value'] ? date('d-m-Y H:i', $value['old_value']) : $value['old_value'];
                     $data[] = $date && $value['new_value'] ? date('d-m-Y H:i', $value['new_value']) : $value['new_value'];
                     fputcsv($file, $data);
                 }
             } else {
                 $data[] = "Non-relevant";
                 fputcsv($file, $data);
             }
         } else {
             $data[] = "N/A";
             fputcsv($file, $data);
         }
     }
     rewind($file);
     header('Content-type: text/csv');
     header('Content-disposition: filename=Export.csv');
     fpassthru($file);
     fclose($file);
     die;
 }
Пример #9
0
        <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>
Пример #10
0
 public function action_index()
 {
     $ids = array_keys(Arr::get($_POST, 'job', array()));
     if (!$ids) {
         throw new HTTP_Exception_404('Not found');
     }
     $regs = DB::select('region_id')->from('user_regions')->where('user_id', '=', User::current('id'))->execute()->as_array('region_id', 'region_id');
     $query = array();
     if ($regs) {
         $query['region'] = array('$in' => array_values($regs));
     }
     if (!Group::current('show_all_jobs')) {
         $query['$or'] = array(array('ex' => intval(User::current('company_id'))), array('companies' => intval(User::current('company_id'))));
     }
     $query['_id'] = array('$in' => $ids);
     $jobs = Database_Mongo::collection('jobs')->find($query);
     $static = array_flip(explode(',', Group::current('columns')));
     $header = array('Ticket ID');
     $types = DB::select('id', 'name')->from('job_types')->execute()->as_array('id', 'name');
     $companies = DB::select('id', 'name')->from('companies')->execute()->as_array('id', 'name');
     if ($ids) {
         $attachments = DB::select('job_id', DB::expr('COUNT(*) as cnt'))->from('attachments')->where('job_id', 'IN', $ids)->and_where('uploaded', '>', 0)->group_by('job_id')->execute()->as_array('job_id', 'cnt');
     } else {
         $attachments = array();
     }
     if (Group::current('allow_assign')) {
         $result = Database_Mongo::collection('submissions')->aggregate(array(array('$match' => array('job_key' => array('$in' => $ids), 'active' => 1)), array('$group' => array('_id' => '$job_key', 'count' => array('$sum' => 1)))));
         $submissions = array();
         foreach (Arr::get($result, 'result', array()) as $value) {
             $submissions[$value['_id']] = $value['count'];
         }
     }
     if (isset($static['last_update'])) {
         $header[] = 'Last update';
     }
     if (isset($static['last_submit'])) {
         $header[] = 'Last submit';
     }
     if (isset($static['status']) && Group::current('show_all_jobs')) {
         $header[] = 'Job status';
     }
     if (isset($static['types'])) {
         $header[] = 'Assigned works';
     }
     if (isset($static['companies'])) {
         $header[] = 'Assigned companies';
     }
     if (isset($static['pending'])) {
         $header[] = 'Pending submissions';
     }
     if (isset($static['attachments'])) {
         $header[] = 'Attachments';
     }
     foreach (Columns::get_search() as $id => $type) {
         $header[] = Columns::get_name($id);
     }
     $list = array();
     $request = array();
     foreach ($jobs as $job) {
         if (!isset($job['lat'])) {
             $request[$job['_id']] = Arr::path($job, 'data.8');
         }
     }
     if ($request) {
         $coords = MapQuest::locate($request);
         foreach ($coords as $key => $value) {
             Database_Mongo::collection('jobs')->update(array('_id' => $key), array('$set' => array('lng' => $value['lng'], 'lat' => $value['lat'])));
         }
     } else {
         $coords = array();
     }
     foreach ($jobs as $ticket) {
         if (isset($coords[$ticket['_id']])) {
             $ticket['lng'] = $coords[$ticket['_id']]['lng'];
             $ticket['lat'] = $coords[$ticket['_id']]['lat'];
         }
         if (!isset($ticket['lat'])) {
             continue;
         }
         $row = array($ticket['_id']);
         if (isset($static['last_update'])) {
             $row[] = date('d-m-Y H:i', Arr::get($ticket, 'last_update', $ticket['created']));
         }
         if (isset($static['last_submit'])) {
             $row[] = Arr::get($ticket, 'last_submit') ? date('d-m-Y H:i', $ticket['last_submit']) : '';
         }
         if (isset($static['status']) && Group::current('show_all_jobs')) {
             $row[] = Arr::get(Enums::$statuses, Arr::get($ticket, 'status', 0), 'Unknown');
         }
         if (isset($static['types'])) {
             if (Group::current('allow_assign')) {
                 $row[] = implode(', ', array_intersect_key($types, Arr::get($ticket, 'assigned', array())));
             } else {
                 $row[] = implode(', ', array_intersect_key($types, array_filter(Arr::get($ticket, 'assigned', array()), function ($x) {
                     return $x == User::current('company_id');
                 })));
             }
         }
         if (isset($static['companies'])) {
             $row[] = implode(', ', array_intersect_key($companies, array_flip(Arr::get($ticket, 'assigned', array()))));
         }
         if (isset($static['pending'])) {
             $row[] = Arr::get($submissions, $ticket['_id']);
         }
         if (isset($static['attachments'])) {
             $row[] = Arr::get($attachments, $ticket['_id']);
         }
         foreach (Columns::get_search() as $id => $type) {
             $row[] = Arr::path($ticket, array('data', $id)) ? Columns::output($ticket['data'][$id], Columns::get_type($id), true) : '';
         }
         $row = array_combine($header, $row);
         $row['lat'] = $ticket['lat'];
         $row['lng'] = $ticket['lng'];
         $list[] = $row;
     }
     if (!$list) {
         throw new HTTP_Exception_404('Not found');
     }
     DB::delete('maps')->where('expire', '<', time())->execute();
     $ids = DB::select('map_id')->distinct(true)->from('maps')->execute()->as_array('map_id', 'map_id');
     do {
         $id = Text::random('alnum', 32);
     } while (isset($ids[$id]));
     $expire = time() + 60 * 60 * 24 * 7;
     $query = DB::insert('maps', array('map_id', 'job_key', 'lng', 'lat', 'info', 'expire'));
     foreach ($list as $values) {
         $lat = $values['lat'];
         $lng = $values['lng'];
         unset($values['lng']);
         unset($values['lat']);
         $query->values(array($id, $values['Ticket ID'], $lng, $lat, json_encode($values), $expire));
     }
     $query->execute();
     $this->redirect('/map.html#' . $id);
 }
Пример #11
0
 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);
 }
Пример #12
0
 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);
 }
Пример #13
0
 public static function calculate_financial($job)
 {
     $columns = array_map(function ($val) {
         return 'data.' . $val;
     }, array_keys(Columns::get_financial()));
     $submissions = Database_Mongo::collection('submissions')->find(array('job_key' => $job['_id'], 'key' => array('$in' => $columns)))->sort(array('update_time' => -1));
     $columns = Columns::get_financial();
     $data = array('rev' => 0, 'ecost' => 0, 'acost' => 0);
     $rates = array();
     $result = DB::select()->from('rates')->execute();
     foreach ($result as $row) {
         $rates[$row['company_id']][$row['region_id']][$row['column_id']] = $row['rate'];
     }
     $companies = DB::select('id', 'company_id')->from('users')->execute()->as_array('id', 'company_id');
     $client = array();
     foreach ($columns as $column => $max) {
         $client[$column] = isset($rates[0][$job['region']][$column]) ? $rates[0][$job['region']][$column] : (isset($rates[0][0][$column]) ? $rates[0][0][$column] : 0);
     }
     foreach (Columns::get_financial() as $column => $max) {
         $data['rev'] += Arr::path($job, array('data', $column), 0) * $client[$column];
     }
     $used = array();
     foreach ($submissions as $submission) {
         $company = Arr::get($companies, $submission['user_id']);
         if (!$company || !isset($rates[$company])) {
             continue;
         }
         $rate = $rates[$company];
         $key = substr($submission['key'], 5);
         if (isset($used[$key])) {
             continue;
         }
         $used[$key] = true;
         if (isset($submission['paid'])) {
             $data['acost'] += round($submission['paid'] * $submission['rate'], 2);
             $data['ecost'] += round($submission['paid'] * $submission['rate'], 2);
             continue;
         }
         $rate = isset($rate[$job['region']][$key]) ? $rate[$job['region']][$key] : (isset($rate[0][$key]) ? $rate[0][$key] : 0);
         if (!$rate) {
             continue;
         }
         $value = min(floatval($submission['value']), $columns[$key]);
         $data['ecost'] += round($value * $rate, 2);
     }
     $data['apcost'] = $data['ecost'];
     if (!isset($used['205']) && Arr::get($job['data'], '205')) {
         $max = 0;
         $list = array_merge(Arr::get($job, 'companies', array()), Arr::get($job, 'ex', array()));
         foreach ($list as $company) {
             if (!isset($rates[$company])) {
                 continue;
             }
             $rate = $rates[$company];
             $max = max($max, isset($rate[$job['region']]['205']) ? $rate[$job['region']]['205'] : (isset($rate[0]['205']) ? $rate[0]['205'] : 0));
         }
         $data['apcost'] += round(0.85 * $max, 2);
     }
     $data['egp'] = $data['rev'] - $data['ecost'];
     $data['gp'] = $data['rev'] - $data['acost'];
     $result = array();
     if (Arr::get($job['data'], 258, 0) != $data['rev']) {
         $result['$set']['data.258'] = $data['rev'];
     }
     if (Arr::get($job['data'], 259, 0) != $data['ecost']) {
         $result['$set']['data.259'] = $data['ecost'];
     }
     if (Arr::get($job['data'], 260, 0) != $data['acost']) {
         $result['$set']['data.260'] = $data['acost'];
     }
     if (Arr::get($job['data'], 261, 0) != $data['egp']) {
         $result['$set']['data.261'] = $data['egp'];
     }
     if (Arr::get($job['data'], 262, 0) != $data['gp']) {
         $result['$set']['data.262'] = $data['gp'];
     }
     if (Arr::get($job['data'], 267, 0) != $data['apcost']) {
         $result['$set']['data.267'] = $data['apcost'];
     }
     $target = DB::select(DB::expr('SUM(`amount`) as total'))->from('payment_jobs')->where('job_key', '=', $job['_id'])->execute()->get('total');
     if ($target) {
         if ($data['acost'] > $target) {
             if (!isset($job['partial'])) {
                 $result['$set']['partial'] = 1;
             }
             if (isset($job['paid'])) {
                 $result['$unset']['paid'] = 1;
             }
         } else {
             if (isset($job['partial'])) {
                 $result['$unset']['partial'] = 1;
             }
             if (!isset($job['paid'])) {
                 $result['$set']['paid'] = 1;
             }
         }
     } else {
         if (isset($job['partial'])) {
             $result['$unset']['partial'] = 1;
         }
         if (isset($job['paid'])) {
             $result['$unset']['paid'] = 1;
         }
     }
     if ($result) {
         Database_Mongo::collection('jobs')->update(array('_id' => $job['_id']), $result);
     }
 }
Пример #14
0
 /**
  * @depends testCreation
  */
 public function testCorrectMysql(Columns $columns)
 {
     $columns->setSymbols(Columns::MYSQL);
     $this->assertEquals($columns->toString(), '`a`, `b`, `c`');
 }
Пример #15
0
 public function action_index()
 {
     $id = $this->request->param('id');
     $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');
     }
     if (!Group::current('show_all_jobs') && !in_array((int) User::current('company_id'), Arr::get($job, 'companies', array()), true)) {
         Columns::set_readonly();
     }
     $job['attachments'] = DB::select()->from('attachments')->where('job_id', '=', $id)->and_where('uploaded', '>', '0')->order_by('folder', 'asc')->order_by('numbering', 'asc')->execute()->as_array('id');
     if (isset($_GET['delete']) && Group::current('allow_assign')) {
         $file_id = intval($_GET['delete']);
         if (isset($job['attachments'][$file_id])) {
             if (file_exists(DOCROOT . 'storage/' . $file_id)) {
                 unlink(DOCROOT . 'storage/' . $file_id);
             }
             $attachment = $job['attachments'][$file_id];
             $data = array('filename' => $attachment['folder'] . ' / ' . $attachment['fda_id'] . ' / ' . $attachment['address'] . ' / ' . $attachment['filename'], 'uploaded' => time(), 'user_id' => User::current('id'), 'job_id' => $id, 'action' => 2);
             Database::instance()->begin();
             DB::insert('upload_log', array_keys($data))->values(array_values($data))->execute();
             DB::delete('attachments')->where('id', '=', $file_id)->execute();
             Database::instance()->commit();
             die(json_encode(array('success' => true)));
         } else {
             throw new HTTP_Exception_404('Not found');
         }
     }
     $users = array();
     $job['region'] = DB::select('name')->from('regions')->where('id', '=', $job['region'])->execute()->get('name');
     $tabs = DB::select()->from('job_tabs')->execute()->as_array('id');
     foreach ($job['attachments'] as $attachment) {
         $users[$attachment['user_id']] = 1;
     }
     $job_types = DB::select('id', 'name')->from('job_types')->order_by('name', 'asc')->execute()->as_array('id', 'name');
     $companies = DB::select('id', 'name')->from('companies')->order_by('name', 'asc')->execute()->as_array('id', 'name');
     $submissions = array();
     if (Group::current('allow_assign')) {
         $result = Database_Mongo::collection('submissions')->find(array('job_key' => $id))->sort(array('update_time' => -1, 'user_id' => 1, 'key' => 1));
     } else {
         $u = DB::select('id')->from('users')->where('company_id', '=', User::current('company_id'))->execute()->as_array(NULL, 'id');
         $result = Database_Mongo::collection('submissions')->find(array('job_key' => $id, 'user_id' => array('$in' => $u)))->sort(array('update_time' => -1, 'user_id' => 1, 'key' => 1));
     }
     foreach ($result as $submission) {
         $users[$submission['user_id']] = 1;
         $key = substr($submission['key'], 5);
         $data = array('id' => $submission['_id'], 'key' => str_replace('.', '-', $submission['key']), 'user_id' => $submission['user_id'], 'time' => $submission['update_time'], 'name' => Columns::get_name($key), 'type' => Columns::get_type($key), 'active' => Arr::get($submission, 'active'), 'value' => $submission['value']);
         if (isset($submission['version'])) {
             $data['version'] = $submission['version'];
         }
         if (Group::current('allow_assign') && Arr::get($submission, 'active') == 1) {
             $tabs[Columns::get_tab($key)]['submissions'][$key] = 1;
             $submissions[$submission['key']][] = $data;
         }
         $submissions['list'][(string) $data['id']] = $data;
     }
     foreach (Columns::get_visible() as $key => $name) {
         $tabs[Columns::get_tab($key)]['columns'][$key] = $name;
     }
     User::get(array_keys($users));
     if ($_POST) {
         $update_time = time();
         if (!Arr::path($_FILES, 'attachment.error', -1) && is_uploaded_file($_FILES['attachment']['tmp_name'])) {
             $data = array('filename' => $_FILES['attachment']['name'], 'mime' => $_FILES['attachment']['type'], 'uploaded' => $update_time, 'user_id' => User::current('id'), 'job_id' => $id);
             Database::instance()->begin();
             $result = DB::insert('attachments', array_keys($data))->values(array_values($data))->execute();
             $image_id = Arr::get($result, 0);
             if ($image_id && move_uploaded_file($_FILES['attachment']['tmp_name'], DOCROOT . 'storage/' . $image_id)) {
                 Database::instance()->commit();
                 Messages::save("File " . $data['filename'] . ' was successfully uploaded!', 'success');
             } else {
                 Database::instance()->rollback();
             }
         }
         if (Group::current('allow_assign')) {
             $update = array();
             $archive = array();
             foreach (Arr::get($_POST, 'data', array()) as $key => $value) {
                 $value = Columns::parse($value, Columns::get_type($key));
                 if (Arr::path($job, 'data.' . $key) != $value) {
                     if ($value) {
                         $update['$set']['data.' . $key] = $value;
                     } else {
                         $update['$unset']['data.' . $key] = 1;
                     }
                     $archive['data'][$key] = array('old_value' => Arr::path($job, 'data.' . $key), 'new_value' => $value);
                     $job['data'][$key] = $value;
                 }
             }
             $list = Arr::get($submissions, 'list', array());
             $pending = array();
             $accepted = array();
             $ignored = array();
             foreach ($list as $submission) {
                 $key = 'submission-' . str_replace('-', '.', $submission['key']);
                 $value = Arr::path($_POST, $key);
                 if ($value !== NULL) {
                     $pending[] = $submission['id'];
                     if ($value) {
                         $accepted[] = $submission['id'];
                     } else {
                         $ignored[] = $submission['id'];
                     }
                 }
             }
             foreach (Arr::get($_POST, 'submission-data', array()) as $key => $value) {
                 if ($value && isset($list[$value])) {
                     $value = Arr::path($list, $value . '.value');
                     if ($key == 177 || $key == 205) {
                         $value = $value ? 1 : 0;
                     }
                     if (Arr::path($job, 'data.' . $key) != $value) {
                         if ($value) {
                             $update['$set']['data.' . $key] = $value;
                             unset($update['$unset']['data.' . $key]);
                         } else {
                             $update['$unset']['data.' . $key] = 1;
                             unset($update['$set']['data.' . $key]);
                         }
                         $archive['data'][$key] = array('old_value' => Arr::path($job, 'data.' . $key), 'new_value' => $value);
                         $job['data'][$key] = $value;
                     }
                 }
             }
             if ($pending) {
                 Database_Mongo::collection('submissions')->update(array('_id' => array('$in' => $ignored)), array('$set' => array('admin_id' => User::current('id'), 'process_time' => $update_time), '$unset' => array('active' => 1)), array('multiple' => 1));
                 Database_Mongo::collection('submissions')->update(array('_id' => array('$in' => $accepted)), array('$set' => array('admin_id' => User::current('id'), 'process_time' => $update_time, 'active' => -1)), array('multiple' => 1));
             }
             $ass = false;
             $values = array();
             foreach (Arr::get($_POST, 'assigned', array()) as $key => $value) {
                 if (Arr::path($job, 'assigned.' . $key) != $value) {
                     if ($ass < 1) {
                         $ass = $value ? 1 : -1;
                     }
                     $values[] = array('time' => $update_time, 'user_id' => User::current('id'), 'company_id' => max($value, 0), 'job_id' => $job['_id'], 'type' => $key);
                     $unassigned = Arr::path($job, 'assigned.' . $key);
                     if ($value) {
                         $job['assigned'][$key] = $value;
                         $users = DB::select('id')->from('users')->where('company_id', '=', $value)->execute()->as_array(NULL, 'id');
                         $update['$set']['data.266'] = $update_time;
                         $message = '1 ticket was allocated on ' . date('d-m-Y H:i', $update_time) . '. <a href="' . URL::base() . 'search/view/' . $job['_id'] . '">View ticket</a>';
                         $insert = DB::insert('notifications', array('user_id', 'message'));
                         foreach ($users as $user) {
                             $insert->values(array($user, $message));
                         }
                         $insert->execute();
                     } else {
                         unset($job['assigned'][$key]);
                     }
                     if ($unassigned) {
                         $users = DB::select('id')->from('users')->where('company_id', '=', $unassigned)->execute()->as_array(NULL, 'id');
                         $subs = Database_Mongo::collection('submissions')->findOne(array('job_key' => $job['_id'], 'active' => 1));
                         if ($subs) {
                             Messages::save('Unable to unassign the job - please, approve or reject all submissions first!', 'danger');
                         } else {
                             $subs = Database_Mongo::collection('submissions')->find(array('job_key' => $job['_id'], 'user_id' => array('$in' => $users), 'financial' => array('$exists' => 0), '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');
                             $result = array();
                             foreach ($financial as $column) {
                                 if (isset($list['data.' . $column])) {
                                     $result[$column] = $list['data.' . $column];
                                 }
                             }
                             Database_Mongo::collection('submissions')->update(array('_id' => array('$in' => array_values($result))), array('$set' => array('financial_time' => 0)), array('multiple' => 1));
                         }
                     }
                 }
             }
             if ($ass) {
                 $update['$set']['assigned'] = $job['assigned'];
                 $insert = DB::insert('assign_log', array_keys($values[0]));
                 foreach ($values as $value) {
                     $insert->values($value);
                 }
                 $insert->execute();
                 $result = Database_Mongo::collection('submissions')->distinct('user_id', array('job_key' => $job['_id']));
                 if ($result) {
                     $result = DB::select('company_id')->distinct(true)->from('users')->where('id', 'IN', $result)->and_where('company_id', '>', 0)->execute()->as_array(NULL, 'company_id');
                 }
                 $companies = array_flip($result);
                 foreach ($companies as $key => $value) {
                     $companies[$key] = 1;
                 }
                 $update['$set']['ex'] = array_keys($companies);
             }
             if (!Arr::get($update, '$unset')) {
                 unset($update['$unset']);
             }
             $companies = array();
             if (isset($job['assigned'])) {
                 foreach ($job['assigned'] as $company) {
                     if ($company) {
                         $companies[$company] = 1;
                     }
                 }
             }
             foreach (Columns::$settings as $key => $value) {
                 if (!in_array($key, Columns::$settings_read_only, true)) {
                     if (Arr::get($job, $key) != Arr::get($_POST, $key)) {
                         $value = Arr::get($_POST, $key) ? 1 : 0;
                         $update[$value ? '$set' : '$unset'][$key] = 1;
                         $job[$key] = $value;
                     }
                 }
             }
             $discrepancies = Database_Mongo::collection('discrepancies')->find(array('job_key' => $job['_id']))->sort(array('update_time' => -1))->getNext();
             if (Group::current('allow_reports') && $discrepancies) {
                 $fl = 0;
                 $set = array();
                 $ignores = Arr::get($_POST, 'ignore-discrepancy');
                 foreach ($discrepancies['data'] as $key => $values) {
                     $val = Arr::get($values, 'ignore') ? 1 : 0;
                     $new_val = Arr::get($ignores, $key) ? 1 : 0;
                     if ($val != $new_val) {
                         if ($new_val) {
                             if (!$fl) {
                                 $fl = -1;
                             }
                             $set['$set']['data.' . $key . '.ignore'] = 1;
                             $discrepancies['data'][$key]['ignore'] = 1;
                         } else {
                             if ($values['old_value'] != Arr::get($job['data'], $key, '')) {
                                 $fl = 1;
                             }
                             $set['$unset']['data.' . $key . '.ignore'] = 1;
                             $discrepancies['data'][$key]['ignore'] = 0;
                         }
                     }
                 }
                 if ($set) {
                     Database_Mongo::collection('discrepancies')->update(array('_id' => new MongoId($discrepancies['_id'])), $set);
                 }
                 if ($fl > 0 && !Arr::get($job, 'discrepancies')) {
                     $update['$set']['discrepancies'] = 1;
                 } elseif ($fl <= 0 && Arr::get($job, 'discrepancies')) {
                     $fl = true;
                     foreach ($discrepancies['data'] as $key => $values) {
                         if (!Arr::get($values, 'ignore')) {
                             $value = $values['old_value'];
                             $new_value = Arr::get($job['data'], $key, '');
                             if ($key == 44) {
                                 $value = preg_replace('/[^a-z]/i', '', strtolower($value));
                                 $new_value = preg_replace('/[^a-z]/i', '', strtolower($new_value));
                             }
                             if ($value != $new_value) {
                                 $fl = false;
                             }
                         }
                     }
                     if ($fl) {
                         $update['$unset']['discrepancies'] = 1;
                     }
                 }
             }
             if ($update) {
                 Utils::calculate_financial($job);
                 $status = preg_replace('/[^a-z]/', '', strtolower(Arr::path($update, array('$set', 'data.44'), '')));
                 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;
                     }
                 }
                 $update['$set']['companies'] = array_keys($companies);
                 $status = Arr::get($job, 'status', Enums::STATUS_UNALLOC);
                 if ($companies && $status == Enums::STATUS_UNALLOC) {
                     $update['$set']['status'] = Enums::STATUS_ALLOC;
                 } elseif (!$companies && $status == Enums::STATUS_ALLOC) {
                     $update['$unset']['status'] = 1;
                 }
                 $update['$set']['last_update'] = $update_time;
                 if (isset($update['$set']['data.8'])) {
                     $update['$set']['address'] = MapQuest::parse($update['$set']['data.8']);
                 } elseif (isset($update['$unset']['data.8'])) {
                     $update['$unset']['address'] = 1;
                 }
                 Database_Mongo::collection('jobs')->update(array('_id' => $id), $update);
                 if ($archive) {
                     foreach (Columns::get_static() as $key => $value) {
                         $archive['static'][$key] = Arr::path($job, 'data.' . $key);
                     }
                     $archive['fields'] = array_keys($archive['data']);
                     $archive['job_key'] = $id;
                     $archive['user_id'] = User::current('id');
                     $archive['update_time'] = $update_time;
                     $archive['update_type'] = 2;
                     $archive['filename'] = 'MANUAL';
                     Database_Mongo::collection('archive')->insert($archive);
                 }
                 Messages::save("Changes were succesfully saved!", 'success');
             } else {
                 Messages::save("No changes were submitted", 'warning');
             }
             if ($pending) {
                 $count = Database_Mongo::collection('submissions')->find(array('job_key' => $id, 'active' => 1))->count();
                 $status = Arr::get($job, 'status', Enums::STATUS_UNALLOC);
                 if ($status == Enums::STATUS_PENDING && !$count) {
                     $update = array('$set' => array('last_update' => $update_time, 'status' => Enums::STATUS_COMPLETE));
                     Database_Mongo::collection('jobs')->update(array('_id' => $id), $update);
                 }
             } elseif (in_array(Arr::get($job, 'status', Enums::STATUS_UNALLOC), array(Enums::STATUS_UNALLOC, Enums::STATUS_ALLOC))) {
                 if ($companies) {
                     $status = Enums::STATUS_ALLOC;
                 } else {
                     $status = Enums::STATUS_UNALLOC;
                 }
                 if ($status != Arr::get($job, 'status', Enums::STATUS_UNALLOC)) {
                     $update = array('$set' => array('last_update' => $update_time));
                     if ($status == Enums::STATUS_UNALLOC) {
                         $update['$unset']['status'] = 1;
                     } else {
                         $update['$set']['status'] = $status;
                     }
                     Database_Mongo::collection('jobs')->update(array('_id' => $id), $update);
                 }
             } elseif ($ass == 1 && in_array(Arr::get($job, 'status', Enums::STATUS_UNALLOC), array(Enums::STATUS_COMPLETE, Enums::STATUS_ARCHIVE))) {
                 $update = array('$set' => array('last_update' => $update_time, 'status' => Enums::STATUS_ALLOC));
                 Database_Mongo::collection('jobs')->update(array('_id' => $id), $update);
             }
             if ($submissions) {
                 Messages::save(count($pending) . '/' . count($submissions['list']) . ' submission(s) were processed.', 'info');
             }
         } else {
             $submissions = array();
             foreach (Arr::get($_POST, 'data', array()) as $key => $value) {
                 $value = Columns::parse($value, Columns::get_type($key));
                 if (Arr::path($job, 'data.' . $key) != $value) {
                     $submissions[$key] = $value;
                 }
             }
             if ($submissions) {
                 $submission = array('job_key' => $id, 'user_id' => User::current('id'), 'active' => 1, 'update_time' => $update_time);
                 if (Arr::get($_POST, 'location')) {
                     $submission['location'] = $_POST['location'];
                 }
                 $status = Arr::get($job, 'status', Enums::STATUS_UNALLOC);
                 $update = array();
                 $approval = false;
                 $archive = array();
                 foreach ($submissions as $key => $value) {
                     if (Columns::get_direct($key)) {
                         if ($value) {
                             $update['$set']['data.' . $key] = $value;
                         } else {
                             $update['$unset']['data.' . $key] = 1;
                         }
                         $archive['data'][$key] = array('old_value' => Arr::path($job, 'data.' . $key), 'new_value' => $value);
                         $job['data'][$key] = $value;
                         $submission['key'] = 'data.' . $key;
                         $submission['value'] = $value;
                         $submission['active'] = -1;
                         $submission['process_time'] = $submission['update_time'];
                         Database_Mongo::collection('submissions')->insert($submission);
                         unset($submission['process_time']);
                         unset($submission['_id']);
                     } else {
                         $approval = true;
                         if ($status != Enums::STATUS_PENDING) {
                             $status = $update['$set']['status'] = Enums::STATUS_PENDING;
                         }
                         $submission['key'] = 'data.' . $key;
                         $submission['value'] = $value;
                         $submission['active'] = 1;
                         Database_Mongo::collection('submissions')->insert($submission);
                         unset($submission['_id']);
                     }
                 }
                 if ($update) {
                     $update['$set']['last_update'] = $update_time;
                     Database_Mongo::collection('jobs')->update(array('_id' => $id), $update);
                     if ($archive) {
                         foreach (Columns::get_static() as $key => $value) {
                             $archive['static'][$key] = Arr::path($job, 'data.' . $key);
                         }
                         $archive['fields'] = array_keys($archive['data']);
                         $archive['job_key'] = $id;
                         $archive['user_id'] = User::current('id');
                         $archive['update_time'] = $update_time;
                         $archive['update_type'] = 2;
                         $archive['filename'] = 'MANUAL';
                         Database_Mongo::collection('archive')->insert($archive);
                     }
                 }
                 Messages::save("Changes were succesfully submitted. " . ($approval ? 'Manager will review changes and confirm them.' : ''), 'success');
             } else {
                 Messages::save("No changes were submitted", 'warning');
             }
         }
         $this->redirect('/search');
     }
     $values = array();
     if (!Group::current('allow_assign')) {
         $last = Database_Mongo::collection('submissions')->find(array('job_key' => $id, 'active' => 1, 'user_id' => array('$in' => DB::select('id')->from('users')->where('company_id', '=', User::current('company_id'))->execute()->as_array(NULL, 'id'))))->sort(array('update_time' => 1));
         foreach ($last as $submission) {
             $values[str_replace('.', '', $submission['key'])] = $submission['value'];
         }
     }
     $job['discr'] = array();
     if (Group::current('allow_reports')) {
         $job['discr'] = Database_Mongo::collection('discrepancies')->find(array('job_key' => $id))->sort(array('update_time' => -1))->getNext();
     }
     if (Group::current('time_machine')) {
         $result = Database_Mongo::collection('archive')->find(array('job_key' => $job['_id']))->sort(array('update_time' => -1));
         $archive = array();
         $ids = array();
         foreach ($result as $item) {
             $archive[] = $item;
             $ids[Arr::get($item, 'user_id', 0)] = 1;
         }
         User::get(array_keys($ids));
     }
     if (Group::current('allow_finance')) {
         $query = DB::select('company_id', 'payment_time', 'admin_id', array('payments.amount', 'total'), array('payment_jobs.amount', 'amount'))->from('payment_jobs')->join('payments')->on('payment_jobs.payment_id', '=', 'payments.id')->where('job_key', '=', $job['_id'])->order_by('payment_time', 'desc');
         if (!Group::current('show_all_jobs')) {
             $query->and_where('company_id', '=', User::current('company_id'));
         }
         $job['payments'] = $query->execute()->as_array();
         $ids = array();
         foreach ($job['payments'] as $payment) {
             $ids[$payment['admin_id']] = 1;
         }
         if ($ids) {
             User::get(array_keys($ids));
         }
     }
     $forms = array();
     if (Group::current('allow_custom_forms')) {
         $forms = array('job' => $job['_id']);
         if (!Group::current('show_all_jobs')) {
             $forms['company'] = User::current('company_id');
         }
         $result = Database_Mongo::collection('forms-data')->find($forms, array('data' => 0))->sort(array('last_update' => -1));
         $forms = array();
         $ids = array();
         foreach ($result as $form) {
             $ids[$form['form_id']] = 1;
             $forms[] = $form;
         }
         $list = array();
         foreach ($ids as $key => $dummy) {
             $list[] = new MongoId($key);
         }
         $result = Database_Mongo::collection('forms')->find(array('_id' => array('$in' => $list)), array('name' => 1));
         $list = array();
         foreach ($result as $form) {
             $list[strval($form['_id'])] = $form['name'];
         }
         foreach ($forms as $key => $form) {
             if (isset($list[$form['form_id']])) {
                 $forms[$key]['name'] = $list[$form['form_id']];
             }
         }
     }
     $view = View::factory('Jobs/View')->bind('job', $job)->bind('tabs', $tabs)->bind('job_types', $job_types)->bind('companies', $companies)->bind('submissions', $submissions)->bind('values', $values)->bind('archive', $archive)->bind('forms', $forms);
     $this->response->body($view);
 }
Пример #16
0
 public function action_index()
 {
     if (!Group::current('allow_assign')) {
         throw new HTTP_Exception_403('Forbidden');
     }
     header('Content-type: application/json');
     $action = $this->request->param('id');
     $result = array();
     $columns = DB::select('id')->from('job_columns')->where('editable', '=', 1)->execute()->as_array('id', 'id');
     switch ($action) {
         case 'get':
             $data = array();
             $result['columns'] = array();
             foreach ($columns as $column) {
                 $value = array('id' => intval($column), 'name' => Columns::get_name($column));
                 $type = Columns::get_type($column);
                 if (substr($type, 0, 4) == 'enum') {
                     $id = substr($type, 5);
                     $type = Enums::is_multi($id) ? 'multi' : 'list';
                     $value['values'] = array_values(Enums::get_values($id));
                 }
                 $value['type'] = $type ?: 'string';
                 $result['columns'][] = $value;
                 $data[] = 'data.' . $column;
             }
             $ids = explode(',', strval(Arr::get($_GET, 'id', '')));
             $values = array();
             if ($ids) {
                 $query = array('_id' => array('$in' => $ids));
                 if (!Group::current('show_all_jobs')) {
                     $query['companies'] = intval(User::current('company_id'));
                 }
                 $jobs = Database_Mongo::collection('jobs')->find($query, $data);
                 foreach ($jobs as $job) {
                     foreach ($job['data'] as $key => $value) {
                         $job['data'][$key] = Columns::output($value, Columns::get_type($key), true);
                     }
                     $job['id'] = $job['_id'];
                     unset($job['_id']);
                     $values[] = $job;
                 }
             }
             $result['jobs'] = $values;
             break;
         case 'set':
             if (User::current('login') !== Arr::get($_POST, 'username')) {
                 die('Wrong username! Please, check it and submit data again.');
             }
             $data = Arr::get($_POST, 'jobs');
             $values = array();
             foreach ($data as $job) {
                 $id = strval(Arr::get($job, 'id', ''));
                 foreach (Arr::get($job, 'data') as $key => $value) {
                     if (isset($columns[$key])) {
                         $values[$id][$key] = strval($value);
                     }
                 }
             }
             $query = array('_id' => array('$in' => array_keys($values)));
             if (!Group::current('show_all_jobs')) {
                 $query['companies'] = intval(User::current('company_id'));
             }
             $data = array();
             foreach ($columns as $column) {
                 $data['data.' . $column] = 1;
             }
             $count = 0;
             $jobs = Database_Mongo::collection('jobs')->find($query, $data);
             foreach ($jobs as $job) {
                 if (isset($values[$job['_id']])) {
                     $id = $job['_id'];
                     $new = array();
                     $archive = array();
                     foreach ($values[$id] as $key => $value) {
                         $value = $value ? Columns::parse($value, Columns::get_type($key)) : '';
                         $old = Arr::path($job, 'data.' . $key);
                         if (($value || $old) && $value != $old) {
                             if ($value) {
                                 $new['$set']['data.' . $key] = $value;
                             } else {
                                 $new['$unset']['data.' . $key] = 1;
                             }
                             $archive['data'][$key] = array('old_value' => $old, 'new_value' => $value);
                         }
                     }
                     if ($new) {
                         $new['$set']['last_update'] = time();
                         Database_Mongo::collection('jobs')->update(array('_id' => $id), $new);
                         $archive['fields'] = array_keys($archive['data']);
                         $archive['job_key'] = $id;
                         $archive['user_id'] = User::current('id');
                         $archive['update_time'] = time();
                         $archive['update_type'] = 2;
                         $archive['filename'] = 'MANUAL';
                         Database_Mongo::collection('archive')->insert($archive);
                         $count++;
                     }
                 }
             }
             $result = array('success' => true, 'count' => $count);
             break;
     }
     die(json_encode($result));
 }
Пример #17
0
                                        <td <?=strlen($value['new_value']) > 100 ? 'class="shorten"' : ''?>><?=HTML::chars($date ? date("d-m-Y H:i", $value['new_value'] ? : 0) : $value['new_value'])?></td>

                        </tr>
                        <?php endforeach;?>
                    </table>
                </td>
            </tr>

    <?php else:?>
        <tr class="<?=Arr::get($classes, $ticket['update_type'])?> text-center">
            <td><a href="<?=URL::base() . 'imex/reports?ticket=' . $ticket['job_key']?>"><?=$ticket['job_key']?></a></td>
            <td nowrap="nowrap"><?=date('d-m-Y H:i', $ticket['update_time'])?></td>
            <td><?=User::get(Arr::get($ticket, 'user_id'), 'login') ? : 'Unknown'?></td>
            <td><?=Arr::get($actions, $ticket['update_type'])?></td>
            <td><a href="<?=URL::base() . 'imex/reports?file=' . urlencode($ticket['filename'])?>"><?=HTML::chars($ticket['filename'])?></a></td>
            <?php foreach ($reports as $id => $name):?>
            <td><?=Columns::output(Arr::path($ticket, 'static.'.$id), Columns::get_type($id))?></td>
            <?php endforeach;?>
            <td colspan="3">N/A</td>
        </tr>
    <?php endif;?>
    <?php endforeach;?>
</table>
<div class="col-xs-12 text-center">
<?php if (Pager::pages() > 1) echo $pager = View::factory('Pager');?>
</div>
<div class="col-xs-12">
    <a class="pull-right btn btn-simple" href="<?=URL::base()?>imex/reports/export<?=URL::query()?>"><span class="glyphicon glyphicon-export"></span>Export to CSV</a>
</div>
<div class="clearfix">&nbsp;</div>
<?php endif;?>
Пример #18
0
 public function action_process()
 {
     if (!isset($_POST['pos'])) {
         die('Error: file position not defined!');
     }
     $pos = $_POST['pos'];
     $region = Arr::get($_POST, 'region', 0);
     $date = strtotime(Arr::get($_POST, 'date'));
     $tod = Arr::get($_POST, 'tod', 0);
     if ($tod) {
         $date += 18 * 60 * 60;
     }
     $time = $tod ? 'EOD' : 'SOD';
     if ($region > 0) {
         $reg_name = DB::select('name')->from('regions')->where('id', '=', $region)->execute()->get('name');
     } else {
         $reg_name = 'PARTIAL';
     }
     ini_set("memory_limit", "512M");
     $filename = $this->request->param('id');
     if (!$filename || !file_exists(DOCROOT . 'files/' . $filename)) {
         die(json_encode(array('success' => true, 'error' => 'Warning: Import aborted - file not found!')));
     }
     $file = fopen(DOCROOT . '/files/' . $filename, 'r');
     $header = fgetcsv($file);
     $columns = array(-1 => 'Ticket Of Work', 0 => 'Please, select a column...', -2 => '<<< IGNORE >>>');
     $result = DB::select('id', 'name')->from('job_columns')->execute()->as_array('id', 'name');
     foreach ($result as $key => $value) {
         $columns[$key] = $value;
     }
     $map = array('ticketofwork' => -1);
     foreach ($result as $key => $name) {
         $id = preg_replace('/[^a-z0-9]/', '', strtolower($name));
         if (isset($map[$id])) {
             if (is_array($map[$id])) {
                 $map[$id][] = $key;
             } else {
                 $map[$id] = array($map[$id], $key);
             }
         } else {
             $map[$id] = $key;
         }
     }
     foreach ($header as $value) {
         $id = str_replace("(YYYY-MM-DD)", '', $value);
         $id = str_replace("(in m)", '', $id);
         $id = preg_replace('/[^a-z0-9]/', '', strtolower($id));
         foreach ($columns as $key => $name) {
             if (preg_replace('/[^a-z0-9]/', '', strtolower($name)) == $id) {
                 unset($columns[$key]);
                 break;
             }
         }
     }
     $keys = array();
     $data = Arr::get($_POST, 'data', array());
     foreach ($header as $key => $value) {
         $id = str_replace("(YYYY-MM-DD)", '', $value);
         $id = str_replace("(in m)", '', $id);
         $id = preg_replace('/[^a-z0-9]/', '', strtolower($id));
         if (isset($map[$id])) {
             if (is_array($map[$id])) {
                 $keys[$key] = array_shift($map[$id]);
                 if (!$map[$id]) {
                     unset($map[$id]);
                 }
             } else {
                 $keys[$key] = $map[$id];
                 unset($map[$id]);
             }
         } else {
             if (isset($data[$key]) && isset($columns[$data[$key]])) {
                 $keys[$key] = $data[$key];
             }
         }
     }
     if (count($keys) != count($header)) {
         die(json_encode(array('success' => true, 'error' => 'Error: Unable to map all columns!')));
     }
     $primary_key_id = -1;
     foreach ($keys as $key => $id) {
         if ($id == -1) {
             $primary_key_id = $key;
         }
     }
     if ($primary_key_id < 0) {
         die(json_encode(array('success' => true, 'error' => 'Error: Unable to map Ticket ID!')));
     } else {
         unset($keys[$primary_key_id]);
     }
     if ($pos) {
         fseek($file, $pos);
     }
     $types = DB::select('id', 'type')->from('job_columns')->where('csv', '=', 1)->execute()->as_array('id', 'type');
     $static = DB::select('id', 'name')->from('job_columns')->where('csv', '=', 1)->and_where('show_reports', '=', 1)->execute()->as_array('id', 'name');
     $start = microtime(true);
     $inserted = 0;
     $updated = 0;
     $skipped = 0;
     $deleted = 0;
     $update_time = time();
     $jobs = Database_Mongo::collection('jobs');
     $archive = Database_Mongo::collection('archive');
     $ids = Session::instance()->get($filename);
     if ($region > 0 && $ids === NULL && !$pos) {
         $result = $jobs->find(array('region' => $region), array('_id'));
         $ids = array();
         while ($row = $result->next()) {
             $ids[$row['_id']] = 1;
         }
     }
     while (true) {
         $row = fgetcsv($file);
         $id = Arr::get($row, $primary_key_id);
         if ($id && strlen($id) == 15 && substr($id, 0, 3) == 'T1W') {
             try {
                 unset($row[$primary_key_id]);
                 $data = array();
                 foreach ($row as $key => $value) {
                     if ($keys[$key] > 0) {
                         switch (Columns::get_type($keys[$key])) {
                             case 'date':
                             case 'datetime':
                                 $value = $value ? strtotime(str_replace('/', '-', $value)) : '';
                                 break;
                             case 'int':
                                 $value = intval($value);
                                 break;
                             case 'float':
                                 $value = floatval($value);
                                 break;
                             default:
                                 $value = iconv("CP1251", 'UTF-8//ignore', $value);
                                 break;
                         }
                         $data[$keys[$key]] = $value;
                     }
                 }
                 $job = $jobs->findOne(array('_id' => $id));
                 if ($job) {
                     $diff = array();
                     $new = array();
                     foreach ($data as $key => $value) {
                         $old = Arr::get($job['data'], $key, '');
                         if (($old || $value) && $old != $value) {
                             if (!Columns::get_persistent($key)) {
                                 if ($value) {
                                     $new['$set']['data.' . $key] = $value;
                                 } else {
                                     $new['$unset']['data.' . $key] = 1;
                                 }
                             }
                             $diff[$key] = array('old_value' => Arr::get($job['data'], $key), 'new_value' => $value ?: '');
                         }
                     }
                     if (Arr::get($job, 'removed')) {
                         $new['$unset']['removed'] = 1;
                     }
                     if ($diff || $new) {
                         if (isset($data[44])) {
                             $status = preg_replace('/[^a-z]/', '', strtolower(Arr::path($diff, '44.old_value')));
                             $status2 = preg_replace('/[^a-z]/', '', strtolower(Arr::path($new, array('$set', 'data.44'))));
                             $status_updated = isset($new['$set']['data.44']);
                             $discrepancy = array();
                             if ($status_updated && ($status == 'tested' && $status2 != 'tested' || $status == 'built' && ($status2 != 'built' && $status2 != 'tested') || $status != $status2 && in_array($status2, array('deferred', 'dirty', 'heldnbn'), true))) {
                                 $discrepancy[44] = $diff[44];
                             }
                             foreach (Columns::get_track() as $key) {
                                 if ($key != 44 && isset($diff[$key]) && !$diff[$key]['new_value'] && $diff[$key]['old_value']) {
                                     $discrepancy[$key] = $diff[$key];
                                 }
                             }
                             if ($discrepancy) {
                                 $discrepancy = array('job_key' => $id, 'update_time' => $update_time, 'user_id' => User::current('id'), 'filename' => $filename, 'data' => $discrepancy, 'fields' => array_keys($discrepancy));
                                 Database_Mongo::collection('discrepancies')->insert($discrepancy);
                                 Database_Mongo::collection('jobs')->update(array('_id' => $id), array('$set' => array('discrepancies' => $discrepancy['_id'])));
                             }
                         }
                         if ($new) {
                             $status = preg_replace('/[^a-z]/', '', strtolower(Arr::path($new, array('$set', 'data.44'))));
                             if ($status == 'built' && !Arr::path($job, 'data.264')) {
                                 $new['$set']['data.264'] = $update_time;
                             }
                             if ($status == 'tested' && !Arr::path($job, 'data.265')) {
                                 $new['$set']['data.265'] = $update_time;
                                 if (!Arr::path($job, 'data.264')) {
                                     $new['$set']['data.264'] = $update_time;
                                 }
                             }
                             $new['$set']['last_update'] = $update_time;
                             if (isset($new['$set']['data.8'])) {
                                 $new['$set']['address'] = MapQuest::parse($new['$set']['data.8']);
                             } elseif (isset($new['$unset']['data.8'])) {
                                 $new['$unset']['address'] = 1;
                             }
                             $jobs->update(array('_id' => $id), $new);
                             foreach (array_keys($diff) as $key) {
                                 if (Columns::get_persistent($key)) {
                                     unset($diff[$key]);
                                 }
                             }
                             if ($diff) {
                                 $archive->insert(array('job_key' => $id, 'update_time' => $update_time, 'update_type' => 2, 'user_id' => User::current('id'), 'filename' => $filename, 'static' => array_intersect_key($data, $static), 'data' => $diff, 'fields' => array_keys($diff)));
                             }
                             $updated++;
                         } else {
                             $skipped++;
                         }
                     } else {
                         $skipped++;
                     }
                 } elseif ($region > 0) {
                     $inserted++;
                     $job = array('_id' => $id, 'region' => $region, 'created' => $update_time, 'last_update' => $update_time, 'data' => $data);
                     if (isset($data[8])) {
                         $job['address'] = MapQuest::parse($data[8]);
                     }
                     $jobs->insert($job);
                     $archive->insert(array('job_key' => $id, 'update_time' => $update_time, 'update_type' => 1, 'user_id' => User::current('id'), 'filename' => $filename, 'static' => array_intersect_key($data, $static), 'data' => array(), 'fields' => array()));
                 }
                 unset($ids[$id]);
             } catch (Exception $e) {
                 print_r($e);
                 die;
             }
         }
         $pos = ftell($file);
         if (feof($file) || microtime(true) - $start > 1) {
             break;
         }
     }
     $finished = filesize(DOCROOT . '/files/' . $filename) == $pos ? 1 : 0;
     if ($finished) {
         if ($ids && $region > 0 && !isset($_POST['skip-deleted'])) {
             $jobs->update(array('_id' => array('$in' => array_keys($ids))), array('$set' => array('removed' => "1")), array('multiple' => 1));
             $result = $archive->find(array('job_key' => array('$in' => array_keys($ids))), array('job_key', 'update_type', 'update_time'));
             $list = array();
             while ($value = $result->next()) {
                 if (!isset($list[$value['job_key']])) {
                     $list[$value['job_key']] = array('date' => $value['update_time'], 'state' => $value['update_type']);
                 } elseif ($list[$value['job_key']]['date'] < $value['update_time']) {
                     $list[$value['job_key']]['state'] = $value['update_type'];
                 }
             }
             $cnt = 0;
             foreach ($ids as $id => $v) {
                 if (Arr::path($list, array($id, 'state'), 0) != 3) {
                     $cnt++;
                     $values = array('job_key' => $id, 'update_type' => 3, 'update_time' => $update_time, 'user_id' => User::current('id'), 'filename' => $filename, 'data' => array(), 'fields' => array());
                     $archive->insert($values);
                 }
             }
             $deleted = $cnt;
         }
         if (Kohana::$environment == Kohana::PRODUCTION) {
             unlink(DOCROOT . 'files/' . $filename);
         }
     } else {
         Session::instance()->set($filename, $ids);
     }
     $result = array('success' => true, 'time' => microtime(true) - $start, 'memory' => memory_get_peak_usage(true), 'inserted' => $inserted, 'updated' => $updated, 'deleted' => $deleted, 'skipped' => $skipped, 'position' => $pos, 'progress' => $finished ? 100 : number_format($pos * 100 / filesize(DOCROOT . '/files/' . $filename)), 'done' => $finished);
     if ($finished) {
         $result['import_name'] = $reg_name . '_' . date('Ymd', $date) . '_' . $time;
         DB::update('regions')->set(array('last_update' => $date))->where('id', '=', $region)->execute();
     }
     die(json_encode($result));
 }
Пример #19
0
     <th>Status</th>
     <th>Processed</th>
     <th>Company</th>
     <th>Location</th>
     <th>Column name</th>
     <th>Value</th>
     <th>Current value</th>
     <?php if (Group::current('allow_assign')):?>
     <th>&nbsp;</th>
     <?php endif;?>
 </tr>
 <?php foreach ($submissions as $submission): 
     $name = Columns::get_name(substr($submission['key'], 5));
     $type = Columns::get_type(substr($submission['key'], 5));
     $value = Columns::output($submission['value'], $type);
     $current = Columns::output(Arr::path($job, 'data.' . substr($submission['key'], 5)), $type);
     ?>
     <tr class="<?=Arr::get($submission, 'active') ? ($submission['active'] > 0 ? 'bg-warning' : 'bg-success') : 'bg-danger'?>">
         <td><?=date('d-m-Y H:i:s', $submission['update_time'])?></td>
         <td><?=User::get($submission['user_id'], 'login')?></td>
         <td><?=isset($submission['version']) ? 'Mobile app (' . ($submission['version'] ? : 'Unknown') . ')' : 'Web-app'?></td>
         <td><span class="glyphicon glyphicon-<?=Arr::get($submission, 'active') ? ($submission['active'] < 0 ? 'ok text-success' : 'edit text-info') : 'remove text-danger'?>"></span></td>
         <td><?=Arr::get($submission, 'process_time') ? date('d-m-Y H:i:s', $submission['process_time']) . ' by ' . User::get(Arr::get($submission, 'admin_id'), 'login') : ''?></td>
         <td><?=Arr::get($companies, User::get($submission['user_id'], 'company_id'))?></td>
         <td><?=Arr::get($submission, 'location') ? '<a target="_blank" href="https://www.google.com/maps/@' . $submission['location'] . ',19z">Location</a>' : ''?></td>
         <td><?=HTML::chars($name)?></td>
         <td class="<?=strlen($value) > 100 ? 'shorten' : ''?>"><?=$value?></td>
         <td class="<?=strlen($current) > 100 ? 'shorten' : ''?>"><?=$current?></td>
         <?php if (Group::current('allow_assign')):?>
         <td>
             <?php if (!Arr::get($submission, 'active')):?>
Пример #20
0
            </div>
            <div class="modal-body" id="table-row-details">
                <table class="table small">
                    <tr class="text-center tr-header">
                        <th>Ticket ID</th>
                        <?php if (isset($columns['last_update'])):?><th class="hidden-sm hidden-xs">Last update</th><?php endif;?>
                        <?php if (isset($columns['last_submit'])):?><th class="hidden-sm hidden-xs"> Last submit</th><?php endif;?>
                        <?php if (isset($columns['status']) && Group::current('show_all_jobs') && $_GET['status'] == -1):?><th class="hidden-sm hidden-xs">Job status</th><?php endif;?>
                        <?php if (isset($columns['types'])):?><th class="hidden-xs">Assigned works</th><?php endif;?>
                        <?php if (isset($columns['companies'])):?><th class="hidden-sm hidden-xs">Assigned companies</th><?php endif;?>
                        <?php if (isset($columns['ex'])):?><th class="hidden-sm hidden-xs">Previously assigned companies</th><?php endif;?>
                        <?php if (isset($columns['settings'])):?><th class="hidden-sm hidden-xs">Settings</th><?php endif;?>
                        <?php if (isset($columns['pending'])):?><th class="hidden-sm hidden-xs">Pending submissions</th><?php endif;?>
                        <?php if (isset($columns['attachments'])):?><th class="hidden-xs">Attachments</th><?php endif;?>
                        <?php foreach (Columns::get_search() as $id => $type):?>
                        <th><?=Columns::get_name($id)?></th>
                        <?php endforeach;?>
                    </tr>
                    <tr class="text-center tr-body"></tr>
                </table>
            </div>
            <div class="modal-footer" id="tableRowButtons">
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="batchEditModal" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
Пример #21
0
 public function action_fill()
 {
     $id = Arr::get($_GET, 'id');
     if ($id) {
         $filters = array('_id' => new MongoId($id));
         if (!Group::current('show_all_jobs')) {
             $filters['company'] = User::current('company_id');
         }
         $form_data = Database_Mongo::collection('forms-data')->findOne($filters);
         $form_id = $form_data['form_id'];
     } else {
         $data = explode('/', Arr::get($_GET, 'form', ''));
         $form_id = $data[0];
         $form_data = array();
     }
     $form = Database_Mongo::collection('forms')->findOne(array('_id' => new MongoId($form_id)));
     if (!$form) {
         throw new HTTP_Exception_404('Not found');
     }
     if (!$form_data) {
         $form_data['form_id'] = $form_id;
         $form_data['data'] = array();
         foreach ($form['data'] as $key => $table) {
             if (is_array($table) && Arr::get($table, 'type') == 'table') {
                 foreach ($table['data'] as $row => $cells) {
                     foreach ($cells as $cell => $input) {
                         if (Arr::get($input, 'name')) {
                             $form_data['data'][$input['name']] = '';
                         }
                     }
                 }
             }
         }
     }
     switch ($form['type']) {
         case Form::FORM_TYPE_COMMON:
             break;
         case Form::FORM_TYPE_TICKET:
             if (isset($form_data['job'])) {
                 $job_id = $form_data['job'];
             } else {
                 $job_id = $data[1];
                 $form_data['job'] = $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(User::current('company_id'), array_merge(Arr::get($job, 'companies', array()), Arr::get($job, 'ex', array())))) {
                 throw new HTTP_Exception_404('Not found');
             }
             foreach ($form['data'] as $key => $table) {
                 if (is_array($table) && Arr::get($table, 'type') == 'table') {
                     foreach ($table['data'] as $row => $cells) {
                         foreach ($cells as $cell => $input) {
                             switch (Arr::get($input, 'type')) {
                                 case 'ticket':
                                     $form['data'][$key]['data'][$row][$cell]['type'] = 'label';
                                     $form['data'][$key]['data'][$row][$cell]['placeholder'] = Arr::get($input, 'value') ? Columns::output(Arr::path($job, 'data.' . $input['value']), Columns::get_type($input['value'])) : $job['_id'];
                                     $form['data'][$key]['data'][$row][$cell]['destination'] = Arr::get($input, 'destination');
                                     unset($form['data'][$key]['data'][$row][$cell]['value']);
                                     break;
                                 case 'timestamp':
                                     $form['data'][$key]['data'][$row][$cell] = array('type' => 'timestamp', 'placeholder' => Arr::get($form_data, 'last_update') ? date('d-m-Y H:i', $form_data['last_update']) : '', 'destination' => Arr::get($input, 'destination'));
                                     break;
                                 case 'revision':
                                     $form['data'][$key]['data'][$row][$cell] = array('type' => 'revision', 'placeholder' => Arr::get($form_data, 'revision', 1), 'destination' => Arr::get($input, 'destination'));
                                     break;
                             }
                         }
                     }
                 }
             }
             break;
     }
     if (isset($_GET['load']) || isset($_GET['print']) || $_POST) {
         header('Content-type: application/json');
         if (isset($form_data['job'])) {
             $job = Database_Mongo::collection('jobs')->findOne(array('_id' => is_array($form_data['job']) ? array('$in' => $form_data['job']) : $form_data['job']));
         }
         if ($_POST || isset($_GET['print'])) {
             if (isset($_GET['print'])) {
                 $columns = DB::select('id')->from('report_columns')->where('report_id', '=', Arr::get($form, 'report'))->execute()->as_array('id', 'id');
                 $report = array();
                 $colors = array();
                 $update = array();
                 $hide = array();
                 foreach ($form['data'] as $key => $table) {
                     if (is_array($table) && Arr::get($table, 'type') == 'table') {
                         if (Arr::get($table, 'data-related-option') && Arr::get($table, 'data-related-value') != Arr::get($form_data['data'], $table['data-related-option'])) {
                             $hide[] = $key;
                         } else {
                             foreach ($table['data'] as $row => $cells) {
                                 foreach ($cells as $cell => $input) {
                                     switch (Arr::get($input, 'type')) {
                                         case 'revision':
                                             $form['data'][$key]['data'][$row][$cell]['placeholder'] = $input['placeholder'] = Arr::get($form_data, 'revision', 1);
                                             break;
                                         case 'timestamp':
                                             $form['data'][$key]['data'][$row][$cell]['placeholder'] = $input['placeholder'] = Arr::get($form_data, 'last_update') ? date('d-m-Y H:i', $form_data['last_update']) : '';
                                             break;
                                     }
                                     if (Arr::get($input, 'name')) {
                                         $form['data'][$key]['data'][$row][$cell]['value'] = $input['value'] = Arr::path($form_data, array('data', $input['name']), '');
                                     }
                                     if (Arr::get($input, 'destination') && isset($columns[$input['destination']])) {
                                         if (isset($input['colors'])) {
                                             try {
                                                 $list = array_combine(explode(',', $input['options']), explode(',', $input['colors']));
                                                 $color = Arr::get($list, $input['value']);
                                             } catch (Exception $e) {
                                                 $color = false;
                                             }
                                             if ($color) {
                                                 $colors[$input['destination']] = $color;
                                             }
                                         }
                                         $report[$input['destination']] = Arr::get($input, in_array(Arr::get($input, 'type', ''), array('text', 'number', 'float', 'date', 'options')) ? 'value' : 'placeholder');
                                     }
                                     if (Arr::get($input, 'bindValue')) {
                                         $bind = explode(',', $input['bindValue']);
                                         foreach ($bind as $target) {
                                             $update[$target] = array('value' => Arr::get($input, in_array(Arr::get($input, 'type', ''), array('text', 'number', 'float', 'date', 'options')) ? 'value' : 'placeholder'), 'type' => 'replace');
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 foreach ($hide as $key) {
                     unset($form['data'][$key]);
                 }
                 $view = View::factory('Forms/PDF')->bind('name', $form['name'])->bind('form', $form['data'])->set('attachments', Arr::get($form_data, 'attachments', array()));
                 require_once APPPATH . 'mpdf/mpdf.php';
                 $pdf = new mPDF('UTF-8', 'A4');
                 $pdf->ignore_invalid_utf8 = true;
                 $pdf->shrink_tables_to_fit = 1;
                 $pdf->keep_table_proportions = true;
                 $pdf->WriteHTML($view);
                 $content = $pdf->Output('', 'S');
                 $name = trim(preg_replace('/-{2,}/', '-', preg_replace('/[^a-z0-9]/i', '-', $form['name'])), '-');
                 switch ($form['type']) {
                     case Form::FORM_TYPE_COMMON:
                         $jobs = array(0);
                         break;
                     case Form::FORM_TYPE_TICKET:
                         $jobs = array($job['_id']);
                         break;
                 }
                 $company = DB::select('name')->from('companies')->where('id', '=', $form_data['company'])->execute()->get('name');
                 $uploaded = time();
                 $submissions = array();
                 $submission = array('user_id' => User::current('id'), 'active' => 1, 'update_time' => $uploaded);
                 foreach ($jobs as $job) {
                     if ($job) {
                         $job = Database_Mongo::collection('jobs')->findOne(array('_id' => $job), array('data' => 1));
                         $new = array();
                         $archive = array();
                         foreach ($update as $key => $value) {
                             if ($value['type'] == 'append') {
                                 switch (Columns::get_type($key)) {
                                     case 'int':
                                     case 'number':
                                     case 'float':
                                         $value = Arr::path($job, 'data.' . $key, 0) + $value['value'];
                                         break;
                                     default:
                                         $value = Arr::path($job, 'data.' . $key, '') . "\n" . $value['value'];
                                         break;
                                 }
                             } else {
                                 $value = $value['value'];
                             }
                             if ($value) {
                                 $value = Columns::parse($value, Columns::get_type($key));
                             }
                             if (Group::current('allow_assign') || Columns::get_direct($key)) {
                                 if ($value) {
                                     $new['$set']['data.' . $key] = $value;
                                 } else {
                                     $new['$unset']['data.' . $key] = 1;
                                 }
                                 if (!Group::current('allow_assign')) {
                                     $submission['job_key'] = $job['_id'];
                                     $submission['key'] = 'data.' . $key;
                                     $submission['value'] = $value;
                                     $submission['active'] = -1;
                                     $submission['process_time'] = $uploaded;
                                     Database_Mongo::collection('submissions')->insert($submission);
                                     unset($submission['process_time']);
                                     unset($submission['_id']);
                                 }
                                 $archive['data'][$key] = array('old_value' => Arr::path($job, 'data.' . $key, ''), 'new_value' => $value);
                             } else {
                                 $new['$set']['status'] = Enums::STATUS_PENDING;
                                 $submissions[$job['_id']][$key] = $value;
                             }
                         }
                         if ($new) {
                             $new['$set']['last_update'] = $uploaded;
                             Database_Mongo::collection('jobs')->update(array('_id' => $job['_id']), $new);
                             if ($archive) {
                                 $archive['fields'] = array_keys($archive['data']);
                                 $archive['job_key'] = $job['_id'];
                                 $archive['user_id'] = User::current('id');
                                 $archive['update_time'] = $uploaded;
                                 $archive['update_type'] = 2;
                                 $archive['filename'] = 'MANUAL';
                                 Database_Mongo::collection('archive')->insert($archive);
                             }
                         }
                     }
                     $filename = $name . ' (' . $company . ') -' . date('dmY-His') . '.pdf';
                     $data = array('filename' => $filename, 'mime' => 'application/pdf', 'uploaded' => $uploaded, 'user_id' => $form_data['user_id'], 'job_id' => $job ? $job['_id'] : 0, 'folder' => 'Reports', 'fda_id' => $job ? Arr::path($job, 'data.14') : 'Unattached', 'address' => $job ? trim(preg_replace('/-{2,}/', '-', preg_replace('/[^0-9a-z\\-]/i', '-', Arr::path($job, 'data.8'))), '-') : 'Unattached', 'title' => '');
                     Database::instance()->begin();
                     $result = DB::insert('attachments', array_keys($data))->values(array_values($data))->execute();
                     $image_id = Arr::get($result, 0);
                     if ($image_id && file_put_contents(DOCROOT . 'storage/' . $image_id, $content)) {
                         unset($data['mime']);
                         $data = array('filename' => 'Reports / ' . ($job ? Arr::path($job, 'data.14') : 'Unattached') . ' / ' . ($job ? $data['address'] : 'Unattached') . ' / ' . $data['filename'], 'uploaded' => $uploaded, 'user_id' => User::current('id'), 'job_id' => $job ? $job['_id'] : 0, 'action' => 1);
                         DB::insert('upload_log', array_keys($data))->values(array_values($data))->execute();
                         Database::instance()->commit();
                         Database_Mongo::collection('forms-data')->remove(array('_id' => new MongoId($id)));
                         if ($report) {
                             $data = $report;
                             $report = array('report_id' => intval(Arr::get($form, 'report')), 'user_id' => $form_data['user_id'], 'company' => $form_data['company'], 'attachment_id' => $image_id, 'attachment' => $filename, 'uploaded' => $uploaded, 'colors' => $colors);
                             if (Arr::get($form_data, 'attachments')) {
                                 $report['attachments'] = $form_data['attachments'];
                             }
                             if (isset($form_data['geo'])) {
                                 $report['geo'] = $form_data['geo'];
                             }
                             $columns = DB::select('id', 'type')->from('report_columns')->where('report_id', '=', $report['report_id'])->execute()->as_array('id', 'type');
                             foreach ($columns as $key => $value) {
                                 $report[$key] = Arr::get($data, $key) ? Columns::parse($data[$key], $value) : '';
                             }
                             Database_Mongo::collection('reports')->insert($report);
                         }
                     } else {
                         Messages::save('Error occurred during report processing... Please try again later');
                     }
                 }
                 foreach ($submissions as $job_key => $values) {
                     foreach ($values as $key => $value) {
                         $submission['job_key'] = $job_key;
                         $submission['key'] = 'data.' . $key;
                         $submission['value'] = $value;
                         $submission['active'] = 1;
                         Database_Mongo::collection('submissions')->insert($submission);
                         unset($submission['_id']);
                     }
                 }
                 $target = 'attachments';
             } else {
                 $target = 'forms';
                 $fl = false;
                 foreach ($form_data['data'] as $key => $value) {
                     if (Arr::get($_POST, $key) != $value) {
                         $form_data['data'][$key] = Arr::get($_POST, $key);
                         $fl = true;
                     }
                 }
                 if ($fl) {
                     $form_data['last_update'] = time();
                     if (Arr::get($form, 'geo')) {
                         $form_data['geo'] = Arr::get($_POST, 'geo');
                     }
                 }
                 if ($id) {
                     if ($fl) {
                         $form_data['revision']++;
                     }
                     Database_Mongo::collection('forms-data')->update(array('_id' => new MongoId($id)), $form_data);
                 } else {
                     $form_data['created'] = time();
                     $form_data['user_id'] = User::current('id');
                     $form_data['company'] = User::current('company_id');
                     $form_data['revision'] = 1;
                     $form_data['last_update'] = time();
                     Database_Mongo::collection('forms-data')->insert($form_data);
                     $id = strval($form_data['_id']);
                 }
             }
             header('Content-type: application/json');
             switch ($form['type']) {
                 case Form::FORM_TYPE_TICKET:
                     $url = URL::base() . 'search/view/' . $form_data['job'] . '#' . $target;
                     break;
                 case Form::FORM_TYPE_COMMON:
                     $url = URL::base() . 'form/unattached';
                     break;
             }
             die(json_encode(array('success' => true, 'id' => $id, 'url' => $url)));
         }
         foreach ($form['data'] as $key => $table) {
             if (is_array($table) && Arr::get($table, 'type') == 'table') {
                 foreach ($table['data'] as $row => $cells) {
                     foreach ($cells as $cell => $input) {
                         if (Arr::get($input, 'name')) {
                             $form['data'][$key]['data'][$row][$cell]['value'] = Arr::get($form_data['data'], $input['name']);
                         }
                     }
                 }
             }
         }
         die(json_encode(array('form' => $form['data'], 'attachments' => Arr::get($form_data, 'attachments'))));
     }
     $view = View::factory('Forms/Form')->set('form_id', $form_id)->set('id', $id)->set('allow_geo', Arr::get($form, 'geo'))->set('allow_attachment', Arr::get($form, 'attachment'))->set('name', $form['name']);
     $this->response->body($view);
 }
Пример #22
0
        <td><?=User::get(Arr::get($ticket, 'user_id'), 'login') ? : 'Unknown'?></td>
        <td><a href="<?=URL::base() . 'imex/discrepancies?file=' . urlencode($ticket['filename'])?>"><?=HTML::chars($ticket['filename'])?></a></td>
        <?php foreach ($reports as $key => $name):?>
        <td><?=Columns::output(Arr::path($ticket, 'static.'.$key), Columns::get_type($key))?></td>
        <?php endforeach;?>
        <td>
            <table class="table subtable">
                <tr class="same-yellow">
                    <th>Column name</th>
                    <th>Old value</th>
                    <th>New value</th>
                    <th>Current value</th>
                </tr>
                <?php foreach($ticket['data'] as $id => $value): $date = Columns::get_type($id) == 'date';?>
                <tr class="submission <?=$value['old_value'] != $ticket['current'][$id] ? 'rose' : 'same-yellow' . (isset($_GET['discrepancy']) ? ' hidden' : '')?>">
                    <td><?=HTML::chars(Columns::get_name($id));?></td>
                    <td><?=HTML::chars($date ? date("d-m-Y H:i", $value['old_value'] ? : 0) : $value['old_value'])?></td>
                    <td><?=HTML::chars($date ? date("d-m-Y H:i", $value['new_value'] ? : 0) : $value['new_value'])?></td>
                    <td><?=HTML::chars($date ? date("d-m-Y H:i", $ticket['current'][$id] ? : 0) : $ticket['current'][$id])?></td>
                </tr>
                <?php endforeach;?>
            </table>
        </td>
    </tr>
    <?php endforeach;?>
</table>
<div class="col-xs-12 text-center">
<?php if (Pager::pages() > 1) echo $pager = View::factory('Pager');?>
</div>
<div class="col-xs-12">
    <a class="pull-right btn btn-simple export-button" data-url="<?=URL::base()?>imex/discrepancies/export" href="javascript:;"><span class="glyphicon glyphicon-export"></span>Export to CSV</a>
Пример #23
0
    </label>
</div>
<div class="btn-group col-xs-12" id="group-selector" data-toggle="buttons">
    <?php foreach ($groups as $id => $name):?>
        <label class="btn btn-primary">
            <input type="radio" class="export-group" name="group" autocomplete="off" value="<?=$id?>" /> <?=$name?>
        </label>
    <?php endforeach;?>
    <label class="btn btn-primary">
        <input type="radio" class="export-group" name="group" autocomplete="off" value="0" /> Custom
    </label>
</div>
<div class="clearfix">&nbsp;</div>
<div class="col-xs-12">
    <input type="hidden" name="group" id="group-input" value=""/>
    <input type="hidden" name="csv" id="csv-input" value="" />
    <button class="btn btn-success disabled" id="export-button" type="submit">Export</button>
</div>
<div class="clearfix">&nbsp;</div>
<table class="table table-striped hidden" id="columns">
    <?php foreach (Columns::get_all() as $key => $name):?>
    <tr><td>
        <label class="control-label">
            <input type="checkbox" data-csv="<?=Columns::get_csv($key) ? 1 : 0?>" name="columns[<?=$key?>]" />
            <?=$name?>
        </label>
    </td></tr>
    <?php endforeach;?>
</table>
</form>
Пример #24
0
                <td><input type="checkbox" class="select-reports checkbox" data-id="<?=$report['attachment_id']?>"/></td>
                <td><a href="<?=URL::base()?>download/attachment/<?=$report['attachment_id']?>"><?=$report['attachment']?></a></td>
                <?php if ($geo):?>
                    <td>
                        <?php if (Arr::get($report, 'geo')):?>
                        <a target="_blank" href="https://www.google.com/maps/@<?=$report['geo']?>,19z">View on map</a>
                        <?php else:?>
                        &nbsp;
                        <?php endif;?>
                    </td>
                <?php endif;?>
                <?php foreach ($columns as $column):?>
                    <td <?=isset($report['colors'][$column['id']]) ? 'style="background-color: ' . $report['colors'][$column['id']] . ';"' : ''?>
                        <?=Group::current('edit_custom_forms') && $column['visible'] == 'write' ? 'class="editable-form-cell" data-type="' . $column['type'] . '" data-guid="' . $column['id'] . '"' : ''?>>
                        <?=Arr::get($report, $column['id']) ? Columns::output($report[$column['id']], $column['type']) : '&nbsp;'?>
                    </td>
                <?php endforeach;?>
                <?php if ($attachments):?>
                    <td>
                        <?php $i = 0; foreach (Arr::get($report, 'attachments', array()) as $attachment):
                            if ($i++ == 2):?>
                                <div class="popover-block">
                            <?php endif;?>
                            <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:?>
Пример #25
0
 public function output($r = array())
 {
     if (!$this->pages) {
         return;
     }
     // нет записей, выходим
     // дефолтный формат вывода
     $default = array('title_start' => '<h3 class="home-last-page">', 'title_end' => '</h3>', 'date' => 'D, j F Y г. в H:i', 'date_start' => '<span class="date"><time datetime="[page_date_publish_iso]">', 'date_end' => '</time></span>', 'cat_start' => ' | <span class="cat">', 'cat_end' => '</span>', 'cat_sep' => ', ', 'tag_start' => ' | <span class="tag">', 'tag_end' => '</span>', 'tag_sep' => ', ', 'author_start' => '', 'author_end' => '', 'read' => '»»»', 'read_start' => '', 'read_end' => '', 'comments_count_start' => '', 'comments_count_end' => '', 'thumb' => true, 'thumb_width' => 320, 'thumb_height' => 180, 'thumb_class' => 'thumb left', 'placehold' => false, 'placehold_path' => 'http://placehold.it/', 'placehold_pattern' => '[W]x[H].png', 'placehold_file' => false, 'placehold_data_bg' => '#CCCCCC', 'block_start' => '', 'block_end' => '', 'line1' => '[thumb]', 'line1_start' => '', 'line1_end' => '', 'line2' => '[title]', 'line2_start' => '', 'line2_end' => '', 'line3' => '[date] [cat]', 'line3_start' => '<p class="home-last-page-info">', 'line3_end' => '</p>', 'line4' => '', 'line4_start' => '', 'line4_end' => '', 'line5' => '', 'line5_start' => '', 'line5_end' => '', 'content' => true, 'content_chars' => 0, 'content_words' => 0, 'content_cut' => ' ...', 'content_start' => '<div class="mso-page-content">', 'content_end' => '</div>', 'columns' => 0, 'columns_class_row' => 'onerow', 'columns_class_cell' => 'col w1-2', 'clearfix' => false, 'page_start' => '', 'page_end' => '', 'pagination_start' => '', 'pagination_end' => '', 'box_grid' => 0, 'box_grid_class' => 'w50', 'box_grid_box_class' => 'table-box', 'exclude_page_add' => true);
     $r = array_merge($default, $r);
     // объединяем
     // $r = array_map('trim', $r);
     $p = new Page_out();
     // шаблонизатор
     // echo $r['block_start'];
     eval(mso_tmpl_prepare($r['block_start'], false));
     // формат записи
     $p->format('title', $r['title_start'], $r['title_end']);
     $p->format('date', $r['date'], $r['date_start'], $r['date_end']);
     $p->format('author', $r['author_start'], $r['author_end']);
     $p->format('cat', $r['cat_sep'], $r['cat_start'], $r['cat_end']);
     $p->format('tag', $r['tag_sep'], $r['tag_start'], $r['tag_end']);
     $p->format('read', $r['read'], $r['read_start'], $r['read_end']);
     $p->format('comments_count', $r['comments_count_start'], $r['comments_count_end']);
     if ($r['exclude_page_add']) {
         $exclude_page_id = mso_get_val('exclude_page_id');
     }
     if ($r['columns']) {
         $my_columns = new Columns($r['columns'], count($this->pages), $r['columns_class_row']);
     }
     if ($r['box_grid']) {
         $p->box_grid($r['box_grid']);
     }
     foreach ($this->pages as $page) {
         $p->load($page);
         // загружаем данные записи
         if ($r['box_grid']) {
             $p->box_grid_cell($r['box_grid_class'], $r['box_grid_box_class']);
         }
         if ($r['columns']) {
             $my_columns->out($r['columns_class_cell']);
         }
         // echo $r['page_start'];
         eval(mso_tmpl_prepare($r['page_start'], false));
         if ($r['thumb']) {
             // плейсхолд
             if ($r['placehold']) {
                 if ($r['placehold_file']) {
                     if ($r['placehold_file'] == 'data') {
                         // сами генерируем плейсхолд
                         // mso_holder($width = 100, $height = 100, $text = true, $background_color = '#CCCCCC', $text_color = '#777777', $font_size = 5)
                         $t_placehold = mso_holder($r['thumb_width'], $r['thumb_height'], false, $r['placehold_data_bg']);
                     } else {
                         $t_placehold = $r['placehold_path'] . $r['placehold_file'];
                     }
                 } else {
                     $t_placehold_pattern = str_replace('[W]', $r['thumb_width'], $r['placehold_pattern']);
                     $t_placehold_pattern = str_replace('[H]', $r['thumb_height'], $t_placehold_pattern);
                     $t_placehold_pattern = str_replace('[RND]', rand(1, 10), $t_placehold_pattern);
                     $t_placehold = $r['placehold_path'] . $t_placehold_pattern;
                 }
             } else {
                 $t_placehold = false;
             }
             if ($thumb = thumb_generate($p->meta_val('image_for_page'), $r['thumb_width'], $r['thumb_height'], $t_placehold)) {
                 $p->thumb = '<a href="' . mso_page_url($p->val('page_slug')) . '" title="' . htmlspecialchars($p->val('page_title')) . '"><img src="' . $thumb . '" class="' . $r['thumb_class'] . '" alt="' . htmlspecialchars($p->val('page_title')) . '"></a>';
             }
         }
         $p->line($r['line1'], $r['line1_start'], $r['line1_end']);
         $p->line($r['line2'], $r['line2_start'], $r['line2_end']);
         $p->line($r['line3'], $r['line3_start'], $r['line3_end']);
         if ($r['content']) {
             if ($r['content_chars']) {
                 $p->content_chars($r['content_chars'], $r['content_cut'], $r['content_start'], $r['content_end']);
                 // текст обрезанный
             } elseif ($r['content_words']) {
                 $p->content_words($r['content_words'], $r['content_cut'], $r['content_start'], $r['content_end']);
                 // текст обрезанный
             } else {
                 $p->content($r['content_start'], $r['content_end']);
             }
         }
         $p->line($r['line4'], $r['line4_start'], $r['line4_end']);
         $p->line($r['line5'], $r['line5_start'], $r['line5_end']);
         if ($r['clearfix']) {
             $p->clearfix();
         }
         // echo $r['page_end'];
         eval(mso_tmpl_prepare($r['page_end'], false));
         if ($r['columns']) {
             $my_columns->next();
         }
         if ($r['box_grid']) {
             $p->box_grid_next();
         }
         // сохраняем id записей, чтобы их исключить из вывода
         if ($r['exclude_page_add']) {
             $exclude_page_id[] = $p->val('page_id');
         }
     }
     if ($r['columns']) {
         $my_columns->close();
     }
     if ($r['box_grid']) {
         $p->box_grid_end();
     }
     if ($r['exclude_page_add']) {
         mso_set_val('exclude_page_id', $exclude_page_id);
     }
     if ($this->param['pagination']) {
         if (mso_hook_present('pagination')) {
             // echo $r['pagination_start'];
             eval(mso_tmpl_prepare($r['pagination_start'], false));
             mso_hook('pagination', $this->pagination);
             // echo $r['pagination_end'];
             eval(mso_tmpl_prepare($r['pagination_end'], false));
         }
     }
     // echo $r['block_end'];
     eval(mso_tmpl_prepare($r['block_end'], false));
 }
Пример #26
0
 public function action_export()
 {
     $id = $this->request->param('id');
     if ($id == 'all') {
         ini_set('memory_limit', '512M');
     }
     header('Content-type: text/csv');
     header('Content-disposition: filename=Discrepancy.csv');
     $result = $this->get_results($id == 'all');
     $reports = array();
     foreach (Columns::get_static() as $column => $value) {
         $reports[$column] = Columns::get_name($column);
     }
     $file = tmpfile();
     $data = array('Ticket ID', 'Date', 'File name');
     foreach ($reports as $id => $name) {
         $data[] = $name;
     }
     $data[] = "Column name";
     $data[] = "Old value";
     $data[] = "New value";
     $data[] = 'Current value';
     fputcsv($file, $data);
     foreach ($result as $ticket) {
         if (!$ticket['discr'] || !isset($_GET['discrepancy'])) {
             $ticket['update_time'] = date('d-m-Y H:i', $ticket['update_time']);
             $data = array($ticket['job_key'], $ticket['update_time'], $ticket['filename']);
             foreach ($reports as $id => $name) {
                 $data[] = Arr::path($ticket, 'static.' . $id);
             }
             $base = $data;
             foreach ($ticket['data'] as $key => $value) {
                 if (!isset($_GET['discrepancy']) || $ticket['current'][$key] != $value['old_value']) {
                     $data = $base;
                     $date = Columns::get_type($key) == 'date';
                     $data[] = Columns::get_name($key);
                     $data[] = $date && $value['old_value'] ? date('d-m-Y H:i', $value['old_value']) : $value['old_value'];
                     $data[] = $date && $value['new_value'] ? date('d-m-Y H:i', $value['new_value']) : $value['new_value'];
                     $current = $ticket['current'][$key];
                     $data[] = $date && $current ? date('d-m-Y H:i', $current) : $current;
                     fputcsv($file, $data);
                 }
             }
         }
     }
     rewind($file);
     fpassthru($file);
     die;
 }
Пример #27
0
 <tr>
     <th>Search</th>
     <th>Persistent</th>
     <?php foreach($groups as $group):?>
         <th class="text-center">Job view</th>
         <th class="text-center">Search</th>
     <?php endforeach;?>
 </tr>
 <?php endif;?>
 <tr>
     <th class="text-right"><?=HTML::chars($name)?></th>
     <td class="text-left">
         <?=Form::select(NULL, array(0 => 'Don\'t show', 1 => 'Simple filtering', 2 => 'Advanced filtering'), Columns::get_static($id), array('class' => 'column-show', 'data-id' => $id))?>
     </td>
     <td class="text-center">
         <?=Form::checkbox(NULL, NULL, Columns::get_persistent($id) ? true : false, array('class' => 'column-persistent', 'data-id' => $id))?>
     </td>
     <?php foreach ($groups as $group => $name): $value = Arr::path($permissions, array($group, $id)); $value2 = Arr::path($search, array($group, $id));?>
         <td class="text-center">
             <?=Form::select(NULL, Columns::$states, $value, array('class' => 'column-permission', 'data-id' => $id, 'group-id' => $group))?>
         </td>
         <td class="text-center">
             <?=Form::select(NULL, Columns::$searches, $value2, array('class' => 'column-search', 'data-id' => $id, 'group-id' => $group))?>
         </td>
     <?php endforeach;?>
 </tr>
 <?php $cnt++; endforeach;?>
 <tr>
     <th rowspan="2">&nbsp;</th>
     <th>Search</th>
     <th>Persistent</th>
Пример #28
0
 public function action_index()
 {
     define('JOB_STATUS_COLUMN', 'data.44');
     if (!rand(0, 1000)) {
         Database_Mongo::collection('search')->remove(array('expires' => array('$lt' => time())));
     }
     if ($_POST) {
         $data = array('request' => $_POST, 'expires' => time() + 3600);
         Database_Mongo::collection('search')->insert($data);
         $search_id = strval($data['_id']);
         Session::instance()->set('search-settings', $search_id);
         header('Content-type: application/json');
         die(json_encode(array('success' => true, 'id' => $search_id)));
     } elseif (!$_GET && Session::instance()->get('search-settings')) {
         $params = Session::instance()->get('search-settings');
         if (!is_array($params)) {
             $params = json_decode($params);
         }
         if ($params !== NULL) {
             $data = array('request' => $params, 'expires' => time() + 3600);
             Database_Mongo::collection('search')->insert($data);
             $search_id = strval($data['_id']);
             Session::instance()->set('search-settings', $search_id);
         } else {
             $search_id = Session::instance()->get('search-settings');
         }
         if ($search_id) {
             $this->redirect('search?id=' . $search_id);
         }
     } elseif (isset($_GET['clear'])) {
         Session::instance()->delete('search-settings');
         $_GET = array();
     } elseif (isset($_GET['id'])) {
         $data = Database_Mongo::collection('search')->findOne(array('_id' => new MongoId($_GET['id'])));
         if ($data) {
             Session::instance()->set('search-settings', $_GET['id']);
             $_GET = $data['request'];
         } else {
             Session::instance()->delete('search-settings');
         }
     }
     $actions = array('contain', 'does not contain', '=', '<', '<=', '>', '>=', '<>', 'empty', 'not empty');
     $actions_mongo = array('=' => '$eq', '<' => '$lt', '<=' => '$lte', '>' => '$gt', '>=' => '$gte', '<>' => '$ne');
     $columns = Columns::get_visible();
     $reports = Columns::get_static();
     $regs = DB::select('region_id')->from('user_regions')->where('user_id', '=', User::current('id'))->execute()->as_array('region_id', 'region_id');
     $regions = DB::select('id', 'name')->from('regions');
     if ($regs) {
         $regions->where('id', 'IN', $regs);
     }
     $regions = $regions->execute()->as_array('id', 'name');
     $query = array();
     $list_query = array();
     if (Arr::get($_GET, 'submissions')) {
         $result = Database_Mongo::collection('submissions')->aggregate(array(array('$match' => array('active' => 1)), array('$group' => array('_id' => '$job_key'))));
         $result = array_column($result['result'], '_id');
         $query['_id'] = array('$in' => $result);
     }
     if (Group::current('show_all_jobs')) {
         if (Arr::get($_GET, 'company')) {
             $companies = explode(',', $_GET['company']);
             if (count($companies) > 1) {
                 $companies = array('$in' => array_map("intval", $companies));
             } else {
                 $companies = intval($_GET['company']);
             }
             if (Arr::get($_GET, 'ex')) {
                 $list_query['$or'] = $query['$or'] = array(array('companies' => $companies), array('ex' => $companies));
             } else {
                 $list_query['companies'] = $query['companies'] = $companies;
             }
         }
     } else {
         if (Arr::get($_GET, 'status', -1) == 0) {
             $list_query['ex'] = $query['ex'] = intval(User::current('company_id'));
         } else {
             $list_query['companies'] = $query['companies'] = intval(User::current('company_id'));
         }
     }
     if (Group::current('allow_assign')) {
         foreach (Columns::$settings as $key => $value) {
             if (isset($_GET['settings'][$key])) {
                 if ($_GET['settings'][$key]) {
                     $query[$key] = array('$exists' => 1);
                 } else {
                     $query[$key] = array('$exists' => 0);
                 }
             }
         }
     }
     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) {
             $query['_id'] = array('$in' => $q);
         } elseif ($q) {
             $query['_id'] = $q[0];
         }
     }
     if (Arr::get($_GET, 'start')) {
         $query['last_update']['$gt'] = Columns::parse($_GET['start'], 'date');
     }
     if (Arr::get($_GET, 'end')) {
         $query['last_update']['$lt'] = Columns::parse($_GET['end'], 'date');
     }
     if (Arr::get($_GET, 'submit-start')) {
         $query['last_submit']['$gt'] = Columns::parse($_GET['submit-start'], 'date');
     }
     if (Arr::get($_GET, 'submit-end')) {
         $query['last_submit']['$lt'] = Columns::parse($_GET['submit-end'], 'date');
     }
     $status = Arr::get($_GET, 'status', Group::current('allow_assign') ? -1 : Enums::STATUS_ALLOC);
     $_GET['status'] = intval($status);
     if ($status != -1 && (Group::current('show_all_jobs') || $status)) {
         $query['status'] = intval($status) ?: array('$exists' => 0);
     }
     if (!isset($_GET['region'])) {
         $_GET['region'] = User::current('default_region');
     }
     if (Arr::get($_GET, 'region') && (!$regs || isset($regs[$_GET['region']]))) {
         $list_query['region'] = $query['region'] = strval($_GET['region']);
     } elseif ($regs) {
         $list_query['region'] = $query['region'] = array('$in' => array_values($regs));
     }
     if (Arr::get($_GET, 'type')) {
         $query['assigned.' . $_GET['type']] = array('$exists' => 1);
     }
     foreach (Arr::get($_GET, 'columns', array()) as $id => $column) {
         if ($column) {
             $op = Arr::get($actions, Arr::path($_GET, 'actions.' . $id), 0);
             $value = Arr::path($_GET, 'values.' . $id, '');
             $value = Columns::parse($value, Columns::get_type($column));
             if (substr(Columns::get_type($column), 0, 4) == 'enum' && Enums::is_multi(substr(Columns::get_type($column), 5)) && $op == '=' && $value) {
                 $op = 'contain';
             }
             if (Columns::get_type($column) == 'date') {
                 if ($op === 'contain') {
                     $op = '=';
                 } elseif ($op === 'does not contain') {
                     $op = '<>';
                 } elseif ($op == '<=') {
                     $value += 86399;
                 }
                 if ($op == '=' && date('His', $value) === '000000') {
                     $query['data.' . $column]['$lte'] = $value + 86399;
                     $op = '>=';
                 }
             }
             if ($op === 'contain') {
                 $op = '$eq';
                 $value = new MongoRegex('/.*' . preg_replace('/[^a-z0-9,.+:;!? -]/i', '', $value) . '.*/i');
             } elseif ($op === 'does not contain') {
                 $op = '$not';
                 $value = new MongoRegex('/.*' . preg_replace('/[^a-z0-9,.+:;!? -]/i', '', $value) . '.*/i');
             } elseif ($op === 'empty') {
                 $op = '$in';
                 $value = array(NULL, '', 0);
             } elseif ($op === 'not empty') {
                 $op = '$nin';
                 $value = array(NULL, '', 0);
             } else {
                 $op = Arr::get($actions_mongo, $op, '$eq');
             }
             if ($op == '$eq' && !$value) {
                 $value = NULL;
             }
             if (isset($query['data.' . $column]) && $op == '$eq') {
                 if (isset($query['data.' . $column]['$in'])) {
                     $query['data.' . $column]['$in'][] = $value;
                 } elseif (isset($query['data.' . $column]['$eq'])) {
                     $query['data.' . $column] = array('$in' => array($query['data.' . $column]['$eq'], $value));
                 } else {
                     $query['data.' . $column]['$in'] = array($value);
                 }
             } else {
                 $query['data.' . $column][$op] = $value;
             }
         }
     }
     foreach ($query as $key => $ops) {
         if (substr($key, 0, 5) == 'data.' && count($ops) == 1 && key($ops) == '$eq') {
             $query[$key] = array_shift($ops);
         }
     }
     $jobs = Database_Mongo::collection('jobs');
     $list_values = array();
     foreach (Columns::get_search() as $key => $value) {
         if ($value == 2) {
             $list_values[$key] = $jobs->distinct('data.' . $key, $query ?: NULL) ?: array();
             if (substr(Columns::get_type($key), 0, 4) == 'enum') {
                 $list = array();
                 foreach ($list_values[$key] as $values) {
                     if ($values) {
                         $values = explode(', ', $values);
                         foreach ($values as $value) {
                             $list[$value] = 1;
                         }
                     } else {
                         $list[''] = 1;
                     }
                 }
                 $list_values[$key] = array_keys($list);
             }
             if ($list_values[$key]) {
                 sort($list_values[$key]);
             }
         }
     }
     Pager::$count = $jobs->count($query);
     $show = array('region' => 1, 'status' => 1, 'created' => 1, 'last_update' => 1, 'last_submit' => 1, 'assigned' => 1, 'companies' => 1, 'ex' => 1);
     foreach (Columns::$settings as $key => $value) {
         $show[$key] = 1;
     }
     foreach (Columns::get_search() as $column => $type) {
         $show['data.' . $column] = 1;
     }
     $result = $jobs->find($query, $show);
     $sort = Arr::get($_GET, 'sort');
     if (is_array($sort)) {
         $save = implode('|', $sort);
         DB::update('users')->set(array('default_sort' => $save))->where('id', '=', User::current('id'))->execute();
     } else {
         $sort = explode('|', User::current('default_sort') ?: '-update');
         $_GET['sort'] = $sort;
     }
     $sorting = array();
     foreach ($sort as $order) {
         $dir = substr($order, 0, 1) == '-' ? -1 : 1;
         $order = substr($order, 1);
         switch ($order) {
             case 'id':
                 $order = '_id';
                 break;
             case 'update':
                 $order = 'last_update';
                 break;
             case 'submit':
                 $order = 'last_submit';
                 break;
             case 'status':
                 $order = 'status';
                 break;
             case 'data-8':
                 $sorting['address'] = $dir;
                 $order = false;
                 break;
             default:
                 if (substr($order, 0, 5) == 'data-') {
                     $order = 'data.' . intval(substr($order, 5));
                 } else {
                     $order = false;
                 }
         }
         if ($order) {
             $sorting[$order] = $dir;
         }
     }
     $result->sort($sorting)->limit(Pager::limit())->skip(Pager::offset());
     $tickets = array();
     while ($row = $result->next()) {
         $tickets[] = $row;
     }
     $ids = array_column($tickets, '_id');
     $types = DB::select('id', 'name')->from('job_types')->execute()->as_array('id', 'name');
     $companies = DB::select('id', 'name')->from('companies')->execute()->as_array('id', 'name');
     if ($ids) {
         $attachments = DB::select('job_id', DB::expr('COUNT(*) as cnt'))->from('attachments')->where('job_id', 'IN', $ids)->and_where('uploaded', '>', 0)->and_where('folder', '<>', 'Signatures')->group_by('job_id')->execute()->as_array('job_id', 'cnt');
     } else {
         $attachments = array();
     }
     if (Group::current('allow_assign')) {
         $result = Database_Mongo::collection('submissions')->aggregate(array(array('$match' => array('job_key' => array('$in' => $ids), 'active' => 1)), array('$group' => array('_id' => '$job_key', 'count' => array('$sum' => 1)))));
         $submissions = array();
         foreach (Arr::get($result, 'result', array()) as $value) {
             $submissions[$value['_id']] = $value['count'];
         }
     }
     $result = Database_Mongo::collection('forms')->find(array(), array('_id' => 1, 'type' => 1, 'name' => 1));
     $forms = array();
     foreach ($result as $form) {
         $forms[$form['type']][strval($form['_id'])] = $form['name'];
     }
     $view = View::factory('Jobs/Search')->bind('reports', $reports)->bind('regions', $regions)->bind('columns', $columns)->bind('actions', $actions)->bind('tickets', $tickets)->bind('submissions', $submissions)->bind('attachments', $attachments)->bind('list_values', $list_values)->bind('types', $types)->bind('sort', $sort)->bind('companies', $companies)->bind('forms', $forms)->bind('query', $query);
     $this->response->body($view);
 }
Пример #29
0
                    <label><?=$key?>:</label>
                    <div class="width100">
                        <table class="flatten-sub-table width100">
                            <?php foreach ($values as $id => $value): $index = 0; $status = Arr::path($job_values, 'data' . intval($id) . '.status'); $old = Arr::path($job_values, 'data' . intval($id) . '.value'); ?>
                                <?php if (0 == $index++ % 2) :?>
                                    <tr>
                                <?php endif; ?>
                                <td>
                                    <div class="status-cell <?=$status === -1 ? 'bg-success has-success' : ($status === 1 ? 'bg-warning has-warning' : '')?>">
                                        <label class=""><?=$value?>:</label>
                                        <?php if ($old):?>
                                            <br/><label class="old_value control-label <?=strlen($old) > 100 ? 'shorten' : ''?> " >Last submitted value: <span class=""><?=Columns::output($old, Columns::get_type(intval($id)))?></span></label>

                                        <?php endif;?>
                                        <p class="column-value">
                                            <?=Columns::input('data-' . crc32($key) . '[' . $id . ']', NULL, Columns::get_type(intval($id)), $id == 242 ? Arr::path($job, 'data.242') : '', '', Arr::path(Form::$required, array($key, $id)))?>
                                        </p>
                                    </div>
                                </td>
                                <?php if (0 == $index % 2) :?>
                                    </tr>
                                <?php endif; ?>
                            <?php endforeach;?>
                        </table>
                    </div>
                </td>


            <?php if ($tdIndex++==0 && sizeof($columns) == $index): ?>
                <td class="extra"></td>
            <?php endif; ?>
Пример #30
0
        </tr>

        <?php foreach ($list as $submission):
            $key = substr($submission['key'], 5);
            $type = Columns::get_type($key);
            $discr = Group::current('allow_assign') && Arr::path($jobs, $job . '.' . $submission['key']) != $submission['value'];
            $rate = Arr::path($rates, array(User::get($submission['user_id'], 'company_id'), $region, $key), Arr::path($rates, array(User::get($submission['user_id'], 'company_id'), 0, $key), 0));?>
        <tr class="submission text-center <?=$discr ? 'rose' : (Arr::get($_GET, 'discrepancy') ? 'hidden ' : '') .  (Arr::get($submission, 'financial_time') ? 'lgreen' : 'yellow')?>" data-id="<?=$job?>">
            <td><?=date('d-m-Y H:i', $submission['update_time'])?></td>
            <td><?=Arr::get($submission, 'process_time') ? date('d-m-Y H:i', $submission['process_time']) : ''?></td>
            <td class="time"><?=Arr::get($submission, 'financial_time') ? date('d-m-Y H:i', $submission['financial_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 <?=strlen(Columns::output($submission['value'], $type)) > 100 ? 'class="shorten"' : ''?>><?=Columns::output($submission['value'], $type);?></td>
            <?php if (Group::current('allow_assign')):?><td><?=Arr::path($jobs, $job . '.' . $submission['key']) ? Columns::output($jobs[$job]['data'][$key], $type) : ''?></td><?php endif;?>
            <td class="paid"><?=Arr::get($submission, 'paid')?></td>
            <td><?=floatval(Arr::get($columns, $key))?></td>
            <td class="rate"><?=Arr::get($submission, 'rate') ? number_format($submission['rate'], 2) : $rate?></td>
            <?php if (Group::current('allow_assign')):?>
            <td>
                <?php if (!$submission['financial_time'] && $rate):?>
                    <button type="button" data-rate="<?=$rate?>" data-id="<?=$submission['_id']?>" data-value="<?=min(floatval(Arr::get($columns, $key)), floatval($submission['value']) ? : 1)?>" data-max="<?=floatval(Arr::get($columns, $key))?>" class="btn btn-success approve-financial">Approve</button>
                <?php elseif ($submission['financial_time']):?>
                    <button type="button" data-rate="<?=$rate?>" data-id="<?=$submission['_id']?>" data-value="<?=min(floatval(Arr::get($columns, $key)), floatval($submission['value']) ? : 1)?>" data-max="<?=floatval(Arr::get($columns, $key))?>" class="btn btn-warning unapprove-financial">Unapprove</button>
                <?php else: echo '&nbsp;'; endif;?>
            </td>
            <?php endif;?>
        </tr>
        <?php endforeach;?>