Ejemplo n.º 1
0
 function executeTask()
 {
     // do we load a subset or ss vars?
     if (isset($_REQUEST['ss'])) {
         $this->cur_subset = Scrub::variable($_REQUEST['ss']);
     } elseif ($this->subset_default) {
         $this->cur_subset = $this->subset_default;
     }
     // if the table is not set explicitly, look for one in the url
     if (!isset($this->table)) {
         if (isset($_REQUEST['table'])) {
             $this->table = Request::get('table');
             $this->table_url = true;
         } else {
             return false;
         }
     }
     // see if we are calling an action from a link
     $action = Request::get('action');
     if ($action == "action" && isset($this->action_fields[$_GET['f']])) {
         switch ($this->action_fields[$_GET['f']]['type']) {
             case "function":
                 $this->id = intval($_GET['id']);
                 $this->get_row();
                 $this->action_fields[$_GET['f']]['function']($this->list);
                 header("Location: " . $this->createUrl($_GET['ra'], $row[$this->getKey()]));
                 exit;
                 break;
         }
     }
     // check for a singularity, only allow edit/update (this means a user only has access to one of these entries, so there is no list view)
     if ($this->singularity) {
         $row = Database::getInstance()->selectRow($this->table, array($this->singularity => $this->singularityID));
         if (count($row) > 0) {
             $singularity_exists = true;
         }
         if ($singularity_exists) {
             $this->id = $row[$this->getKey()];
         }
         // there can be no "new", "delete", "delconf", "list"
         if ($this->action == "new" || $this->action == "edit" || $this->action == "delete" || $this->action == "delconf" || $this->action == "list" || $this->action == '') {
             if ($singularity_exists) {
                 $this->action = "edit";
             } else {
                 $this->action = "new";
             }
         }
         // if there is no current entry, an edit becomes an insert
         if ($this->action == "update" || $this->action == "insert") {
             if ($singularity_exists) {
                 $this->action = "update";
             } else {
                 $this->action = "insert";
             }
         }
     }
     $this->getKey();
     switch ($this->action) {
         case "pop_return":
             break;
         case "autocomplete":
             $this->loadList();
             $output = array("list" => $this->list, "search" => $_POST['st']);
             echo json_encode($output);
             exit;
             break;
         case "file":
             $this->loadMainFields();
             $field = $_GET['f'];
             $this->get_row();
             if ($this->fields[$field]['type'] == 'file' && count($this->list) > 0) {
                 $file = $this->get_full_file_location($this->fields[$field]['location'], $this->list[$field]);
                 if (!file_exists($file)) {
                     die("No File Uploaded");
                 }
                 switch ($this->list[$this->fields[$field]['extension']]) {
                     case '.pdf':
                         header("Content-Type: application/pdf");
                         break;
                     case '.jpg':
                     case '.jpeg':
                         header("Content-Type: image/jpeg");
                         break;
                     case '.png':
                         header("Content-Type: image/png");
                         break;
                 }
                 readfile($file);
             } else {
                 die('config error');
             }
             exit;
         case "delete":
             if (!$this->deleteable) {
                 // FAILSAFE
                 break;
             }
             if ($this->delconf) {
                 break;
             }
             $_POST['delconf'] = "Yes";
         case "delconf":
             if (!$this->deleteable) {
                 // FAILSAFE
                 break;
             }
             if ($_POST['delconf'] == "Yes") {
             }
         case "list_action":
         case "list":
         case '':
         default:
             $this->action = "list";
             break;
     }
 }