Example #1
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>';
     }
 }
 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;
 }