Beispiel #1
0
 public function edit($mark_id = 0)
 {
     parent::redirectIfWebView();
     // Figure correct way to handle if no mark id
     if (empty($mark_id) || !is_numeric($mark_id)) {
         header('Location: /');
         exit;
     }
     // Check for CSRF
     if ($this->csrf_valid === true) {
         // Figure what options to send for update
         $options = array();
         // 1.6
         // If title is found, attach it
         if (isset($this->db_clean->title)) {
             $options['mark_title'] = $this->db_clean->title;
         }
         // If label ID is found, attach it
         if (isset($this->clean->label_id) && is_numeric($this->clean->label_id)) {
             $options['label_id'] = $this->clean->label_id;
         }
         // If notes are present set them
         if (isset($this->db_clean->notes)) {
             $options['notes'] = $this->db_clean->notes;
             // Check for hashmarks to tags
             $tags = getTagsFromHash($options['notes']);
         }
         // If tags are present, handle differently
         // Need to add to tags table first
         // Then create association
         // If notes are present set them
         if (isset($tags)) {
             parent::addTags($tags, $mark_id);
         }
         // Update users_to_marks record
         $mark = $this->user_marks->update("users_to_marks.user_id = '" . $this->user_id . "' AND users_to_marks.users_to_mark_id = '" . $mark_id . "'", $options);
         // Check if it was updated
         if ($mark === false) {
             $this->data['errors'] = formatErrors(3);
         } else {
             $this->data['mark'] = $mark;
             // Check if label id was set
             // if so get the parent mark id
             // Then add a smart label for this domain
             if (isset($options['label_id']) && !empty($options['label_id'])) {
                 $this->load->model('labels_model', 'labels');
                 $smart_info = getSmartLabelInfo($mark->url);
                 $total = $this->labels->count("labels.user_id = '" . $this->user_id . "' AND labels.smart_key = '" . $smart_info['key'] . "'");
                 // If not found, create it with label
                 // Else update current
                 if ($total < 1 && $options['label_id'] != '1') {
                     $label = $this->labels->create(array('smart_label_id' => $options['label_id'], 'domain' => $smart_info['domain'], 'smart_key' => $smart_info['key'], 'user_id' => $this->user_id));
                 } else {
                     $active = $options['label_id'] == '1' ? '0' : '1';
                     $label = $this->labels->update("labels.user_id = '" . $this->user_id . "' AND labels.smart_key = '" . $smart_info['key'] . "'", array('smart_label_id' => $options['label_id'], 'active' => $active));
                 }
             }
         }
     } else {
         $this->data['errors'] = formatErrors(600);
     }
     // Figure what to do here (api, redirect or generate view)
     $this->renderJSON();
 }