Esempio n. 1
0
 function index()
 {
     $view = new G2_TwigView('pages/index');
     $test_a = R::findOne('audit');
     $args = [];
     if (!empty($_GET)) {
         $wheres = [];
         foreach ($_GET as $field => $value) {
             if (isset($test_a->{$field}) && trim($value)) {
                 $wheres[] = "{$field} LIKE :{$field}";
                 $args[$field] = $value;
             }
         }
         $where = implode(' AND ', $wheres);
     } else {
         $where = '';
     }
     $audits = Audit::deserialize(Mvc_Db::paginate_findAll('audit', 10, "{$where} ORDER BY id DESC", $args));
     // Sort into entities
     $sorted = [];
     foreach ($audits as $audit) {
         // Limit to 10 entries per entity
         if (count($sorted[$audit->entity]) <= 10) {
             $sorted[$audit->entity][] = $audit;
         }
     }
     $view->set('sorted', $sorted);
     $view->entities = R::getCol('SELECT DISTINCT entity FROM audit');
     $view->set_entity = $_GET['entity'];
     $view->page_count = Mvc_Db::get_last_total_pages();
     $view->current = Mvc_Db::get_current_page();
     unset($_GET['p']);
     $view->current_url = PACKAGE_URL . '?' . http_build_query($_GET);
     $view->render();
 }
Esempio n. 2
0
 function create_attachments($attachments)
 {
     $attachments_objs = [];
     $timestamp = time();
     foreach ($attachments as $att) {
         $filename = $att[G2_FormMagic::FILE_NAME];
         $location = $att[G2_FormMagic::FILE_URI];
         if (file_exists($location)) {
             //Determine File name
             //				$filename = basename($file);
             $new_folder = $this->get_package_dir(true) . "mail_attachments/attached-{$timestamp}/{$filename}";
             //Create this new folder
             mkdir(dirname($new_folder), 0777, TRUE);
             //Move file to folder that will be attached
             rename($location, $new_folder);
             //Create the mail attachment db file
             $attachment = Mvc_Db::dispense(self::MAIL_ATTACHMENT);
             $attachment->filename = $filename;
             $attachment->uri = $new_folder;
             Mvc_Db::store($attachment);
             $attachments_objs[] = $attachment;
         }
     }
     return $attachments_objs;
 }