/**
  * @todo Description of function deletePersona
  * @param  $id
  * @param  $batchId
  * @return
  */
 public function delete_persona($id, $batch_id)
 {
     RP_Dao_Factory::get_rp_indi_note_dao($this->prefix)->delete_by_indi_id($id, $batch_id);
     RP_Dao_Factory::get_rp_indi_event_dao($this->prefix)->delete_by_indi_id($id, $batch_id);
     RP_Dao_Factory::get_rp_indi_cite_dao($this->prefix)->delete_by_indi_id($id, $batch_id);
     RP_Dao_Factory::get_rp_indi_name_dao($this->prefix)->delete_by_indi_id($id, $batch_id);
     RP_Dao_Factory::get_rp_indi_dao($this->prefix)->delete($id, $batch_id);
 }
 /**
  *
  * @param RP_Individual_Record $person
  */
 function add_indi($person, $options)
 {
     $need_update = false;
     $indi = new RP_Indi();
     $indi->id = $person->id;
     $indi->batch_id = $this->batch_id;
     $indi->restriction_notice = $person->restriction;
     $indi->gender = $person->gender;
     $indi->perm_rec_file_nbr = $person->perm_rec_file_nbr;
     $indi->anc_rec_file_nbr = $person->anc_file_nbr;
     $indi->auto_rec_id = $person->auto_rec_id;
     $indi->ged_change_date = $person->change_date->date;
     try {
         $person->id = RP_Dao_Factory::get_rp_indi_dao($this->credentials->prefix)->insert($indi);
     } catch (Exception $e) {
         if (stristr($e->getMessage(), 'Duplicate entry') >= 0) {
             $need_update = true;
         } else {
             error_log($e->getMessage() . "::" . RP_Persona_Helper::trace_caller(), 0);
             echo $e->getMessage();
             throw $e;
         }
     }
     if ($need_update) {
         try {
             RP_Dao_Factory::get_rp_indi_dao($this->credentials->prefix)->update($indi);
         } catch (Exception $e) {
             error_log($e->getMessage() . "::" . RP_Persona_Helper::trace_caller(), 0);
             echo $e->getMessage();
             throw $e;
         }
     }
     $this->update_names($person);
     $this->update_indi_events($person);
     $this->update_family_links($person, $options);
     $this->update_notes($person);
     if (isset($person->offspring_id) && !empty($person->offspring_id)) {
         // special case for when rootsperson isSOR
         $this->manageNewParent($person, $options);
     }
     return $person;
 }
 function process_form($credentials, $parms, $options)
 {
     $isSOR = $options['is_system_of_record'] == '1' ? true : false;
     $validator = new Persona_Validator();
     $ret = $validator->validate($parms, $options);
     $options = $ret[1];
     if ($ret[0] !== false) {
         if ($isSOR) {
             $handler = new RP_Gedcom_Loader();
             $handler->credentials = $credentials;
             $handler->batch_id = $ret[0]->batch_id;
             $options['editMode'] = 1;
             $indi = $handler->process_individual($ret[0], $options);
         } else {
             $indi = $ret[0];
         }
         if ($indi instanceof RP_Individual_Record) {
             if (isset($indi->id) && !empty($indi->id)) {
                 $page = $indi->page;
                 if (!isset($page) || empty($page)) {
                     $title = RP_Dao_Factory::get_rp_persona_dao($this->credentials->prefix)->get_fullname($indi->id, $batch_id);
                     $content = "[rootsPersona   personid='{$indi->id}' batchId='{$indi->batch_id}'";
                     for ($i = 1; $i <= 7; $i++) {
                         $pf = 'picfile' . $i;
                         if (isset($indi->images[$i - 1])) {
                             $content = $content . ' ' . $pf . "='" . $indi->images[$i - 1] . "'";
                             $pc = 'piccap' . $i;
                             if (isset($indi->captions[$i - 1])) {
                                 $content = $content . ' ' . $pc . "='" . $indi->captions[$i - 1] . "'";
                             }
                         }
                     }
                     $content = $content . "/]";
                     $page_id = RP_Persona_Helper::add_page(null, $title, $options, null, $content);
                     $indi->page = $page_id;
                     if ($page_id != false) {
                         $this->transaction = new RP_Transaction($credentials);
                         RP_Dao_Factory::get_rp_indi_dao($credentials->prefix)->update_page($indi->id, $indi->batch_id, $page_id);
                         RP_Dao_Factory::get_rp_persona_dao($credentials->prefix)->update_persona_privacy($indi->id, $indi->batch_id, $indi->privacy, '');
                         $this->transaction->commit();
                     }
                 } else {
                     if ($indi->privacy != 'Exc') {
                         $my_post = array();
                         $my_post['ID'] = $page;
                         if ($isSOR) {
                             $title = RP_Dao_Factory::get_rp_persona_dao($this->credentials->prefix)->get_fullname($indi->id, $batch_id);
                             $my_post['post_title'] = $title;
                         }
                         $content = "[rootsPersona   personid='{$indi->id}' batchId='{$indi->batch_id}'";
                         for ($i = 1; $i <= 7; $i++) {
                             $pf = 'picfile' . $i;
                             if (isset($indi->images[$i - 1])) {
                                 $content = $content . ' ' . $pf . "='" . $indi->images[$i - 1] . "'";
                                 $pc = 'piccap' . $i;
                                 if (isset($indi->captions[$i - 1])) {
                                     $content = $content . ' ' . $pc . "='" . $indi->captions[$i - 1] . "'";
                                 }
                             }
                         }
                         $content = $content . "/]";
                         $my_post['post_content'] = $content;
                         wp_update_post($my_post);
                         $this->transaction = new RP_Transaction($credentials);
                         RP_Dao_Factory::get_rp_persona_dao($credentials->prefix)->update_persona_privacy($indi->id, $indi->batch_id, $indi->privacy, '');
                         $this->transaction->commit();
                     } else {
                         wp_delete_post($page);
                         RP_Dao_Factory::get_rp_persona_dao($this->credentials->prefix)->delete_persona($indi->id, $indi->batch_id);
                         $r = array();
                         $r['error'] = 'Persona deleted.';
                         return $r;
                     }
                 }
             }
         } else {
             $r = array();
             $r['error'] = 'Error saving record.';
             return $r;
         }
     } else {
         return $ret[1]['errors'];
     }
     $r = array();
     $r['rp_id'] = $indi->id;
     $r['rp_page'] = $indi->page;
     if (isset($indi->parental->id) && !empty($indi->parental->id)) {
         $r['rp_famc'] = $indi->parental->id;
     }
     if (isset($indi->newFams) && !empty($indi->newFams)) {
         $r['rp_fams'] = $indi->newFams;
     }
     return $r;
 }
示例#4
0
 /**
  *
  * @global wpdb $wpdb
  * @return string
  */
 function add_page_handler()
 {
     try {
         $action = admin_url('/tools.php?page=rootsPersona&rootspage=create');
         $msg = '';
         $options = get_option('persona_plugin');
         $this->transaction = new RP_Transaction($this->credentials, false);
         if (isset($_POST['submitAddPageForm'])) {
             $persons = $_POST['persons'];
             $batch_id = isset($_POST['batch_id']) ? trim(esc_attr($_POST['batch_id'])) : '1';
             if (!isset($persons) || count($persons) == 0) {
                 $msg = __('No people selected.', 'rootspersona');
             } else {
                 foreach ($persons as $p) {
                     $name = RP_Dao_Factory::get_rp_persona_dao($this->credentials->prefix)->get_fullname($p, $batch_id);
                     $pageId = RP_Persona_Helper::add_page($p, $name, $options, $batch_id, null, null);
                     if ($pageId != false) {
                         RP_Dao_Factory::get_rp_indi_dao($this->credentials->prefix)->update_page($p, $batch_id, $pageId);
                         $msg = $msg . '<br/>' . sprintf(__('Page %s created for', 'rootspersona'), $pageId) . ' ' . $p;
                     } else {
                         $msg .= '<br/>' . __('Error creating page for', 'rootspersona') . ' ' . $p;
                     }
                     set_time_limit(60);
                 }
             }
         }
         $batch_ids = RP_Dao_Factory::get_rp_persona_dao($this->credentials->prefix)->get_batch_ids();
         if (isset($_GET['batch_id'])) {
             $batch_ids[0] = $_GET['batch_id'];
         } else {
             if (count($batch_ids) == 0) {
                 $batch_ids[0] = 1;
             }
         }
         $builder = new RP_Add_Page_Builder();
         $persons = RP_Dao_Factory::get_rp_persona_dao($this->credentials->prefix)->get_persons_no_page($batch_ids[0]);
         $retStr = $builder->build($action, $persons, $msg, $options, $batch_ids);
         $this->transaction->commit();
         return $retStr;
     } catch (Exception $e) {
         error_log($e->getMessage() . "::" . RP_Persona_Helper::trace_caller(), 0);
         return '<span style="color:red;margin-top:20px;display:inline-block;">' . $e->getMessage() . "::" . RP_Persona_Helper::trace_caller() . '</span>';
     }
 }
 /**
  *
  * @param array $options
  * @return string
  */
 function delete_pages($options, $batch_id)
 {
     $args = array('numberposts' => -1, 'post_type' => 'page', 'post_status' => 'any');
     $pages = get_posts($args);
     $cnt = 0;
     $force_delete = true;
     foreach ($pages as $page) {
         if (preg_match("/rootsPersona |rootsEvidencePage |rootsPersonaHeader /", $page->post_content)) {
             if (preg_match("/batch[i|I]d=['|\"]" . $batch_id . "['|\"]/", $page->post_content)) {
                 wp_delete_post($page->ID, $force_delete);
                 $cnt++;
                 set_time_limit(60);
             }
         }
     }
     $this->transaction = new RP_Transaction($this->credentials, false);
     RP_Dao_Factory::get_rp_indi_dao($this->credentials->prefix)->unlink_all_pages($batch_id);
     RP_Dao_Factory::get_rp_source_dao($this->credentials->prefix)->unlink_all_pages($batch_id);
     $this->transaction->commit();
     $block = "<div style='overflow:hidden;width:60%;margin:40px;'>" . $cnt . ' ' . sprintf(__('pages deleted from batchId %s', 'rootspersona'), $batch_id) . "<br/>" . "<div style='text-align:center;padding:.5em;margin-top:.5em;'>" . "<span class='rp_linkbutton'  " . RP_Tools_Page_Builder::hover . " style='width:200px;border:2px outset orange;padding:5px;'><a href=' " . admin_url() . "tools.php?page=rootsPersona&rootspage=util" . "&utilityAction=deldata&batch_id=" . $batch_id . "'>" . __('Deleta Data From Database?', 'rootspersona') . "</a></span>" . "<span style='display:inline-block;width:5em;'>&#160;</span>" . "<span class='rp_linkbutton'  " . RP_Tools_Page_Builder::hover . " style='border:2px outset orange;padding:5px;' onclick='window.open(\"" . admin_url('/tools.php?page=rootsPersona') . "\");'><a href=' " . admin_url() . "tools.php?page=rootsPersona'>" . __('Return', 'rootspersona') . "</a></span>" . "</div></div>";
     return $block;
 }