/** \brief Create a structure entry with the given name
       \param parent_id The parent entry to add this to.
            If NULL, create new structure.
       \param after_ref_id The entry to add this one after.
            If NULL, put it in position 0.
       \param name The wiki page to reference
       \param alias An alias for the wiki page name.
       \return the new entries page_ref_id or null if not created.
   */
 function s_create_page($parent_id, $after_ref_id, $name, $alias = '')
 {
     global $prefs;
     $ret = null;
     // If the page doesn't exist then create a new wiki page!
     $newpagebody = tra("Table of contents") . ":" . "{toc}";
     $created = $this->create_page($name, 0, $newpagebody, $this->now, tra('created from structure'), 'system', '0.0.0.0', '', false, '', array('parent_id' => $parent_id));
     // if were not trying to add a duplicate structure head
     if ($created or isset($parent_id)) {
         //Get the page Id
         $query = 'select `page_id` from `tiki_pages` where `pageName`=?';
         $page_id = $this->getOne($query, array($name));
         if (isset($after_ref_id)) {
             $max = $this->getOne('select `pos` from `tiki_structures` where `page_ref_id`=?', array((int) $after_ref_id));
         } else {
             $max = 0;
         }
         if ($max > 0) {
             //If max is 5 then we are inserting after position 5 so we'll insert 5 and move all
             // the others
             $query = 'update `tiki_structures` set `pos`=`pos`+1 where `pos`>? and `parent_id`=?';
             $result = $this->query($query, array((int) $max, (int) $parent_id));
         }
         //Create a new structure entry
         $max++;
         $query = 'insert into `tiki_structures`(`parent_id`,`page_id`,`page_alias`,`pos`) values(?,?,?,?)';
         $result = $this->query($query, array((int) $parent_id, (int) $page_id, $alias, (int) $max));
         //Get the page_ref_id just created
         if (isset($parent_id)) {
             $parent_check = ' and `parent_id`=?';
             $attributes = array((int) $page_id, $alias, (int) $max, (int) $parent_id);
         } else {
             $parent_check = ' and (`parent_id` is null or `parent_id`=0)';
             $attributes = array((int) $page_id, $alias, (int) $max);
         }
         $query = 'select `page_ref_id` from `tiki_structures` ';
         $query .= 'where `page_id`=? and `page_alias`=? and `pos`=?';
         $query .= $parent_check;
         $ret = $this->getOne($query, $attributes);
         if ($prefs['feature_user_watches'] == 'y') {
             include_once 'lib/notifications/notificationemaillib.php';
             sendStructureEmailNotification(array('action' => 'add', 'page_ref_id' => $ret, 'name' => $name));
         }
     }
     return $ret;
 }
Example #2
0
 /** \brief Create a structure entry with the given name
       \param parent_id The parent entry to add this to.
            If NULL, create new structure.
       \param after_ref_id The entry to add this one after.
            If NULL, put it in position 0.
       \param name The wiki page to reference
       \param alias An alias for the wiki page name.
       \return the new entries page_ref_id or null if not created.
 	*/
 public function s_create_page($parent_id, $after_ref_id, $name, $alias = '', $structure_id = null, $options = array())
 {
     global $prefs;
     $ret = null;
     $hide_toc = isset($options['hide_toc']) ? $options['hide_toc'] : 'n';
     $creator = isset($options['creator']) ? $options['creator'] : tra('system');
     $creator_msg = isset($options['creator_msg']) ? $options['creator_msg'] : tra('created from structure');
     $ip_source = isset($options['ip_source']) ? $options['ip_source'] : '0.0.0.0';
     // If the page doesn't exist then create a new wiki page!
     $newpagebody = '';
     if ($hide_toc !== 'y') {
         $newpagebody = tra("Table of contents") . ":" . "{toc}";
     }
     $created = $this->create_page($name, 0, $newpagebody, $this->now, $creator_msg, $creator, $ip_source, '', false, '', array('parent_id' => $parent_id));
     if (!empty($parent_id) || $created || !$this->page_is_in_structure($name)) {
         // if were not trying to add a duplicate structure head
         $query = 'select `page_id` from `tiki_pages` where `pageName`=?';
         $page_id = $this->getOne($query, array($name));
         if (!empty($after_ref_id)) {
             $max = $this->getOne('select `pos` from `tiki_structures` where `page_ref_id`=?', array((int) $after_ref_id));
         } else {
             $max = 0;
         }
         if (!isset($after_ref_id)) {
             // after_ref_id		The entry to add this one after. If NULL, put it in position 0.
             $max = 0;
             $query = 'update `tiki_structures` set `pos`=`pos`+1 where `pos`>? and `parent_id`=?';
             $this->query($query, array((int) $max, (int) $parent_id));
         } elseif ($after_ref_id != 0) {
             if ($max > 0) {
                 //If max is 5 then we are inserting after position 5 so we'll insert 5 and move all
                 // the others
                 $query = 'update `tiki_structures` set `pos`=`pos`+1 where `pos`>? and `parent_id`=?';
                 $result = $this->query($query, array((int) $max, (int) $parent_id));
             }
         } else {
             if (!$created) {
                 $max = $this->getOne('select max(`pos`) from `tiki_structures` where `parent_id`=?', array((int) $parent_id));
             }
         }
         //
         //Create a new structure entry
         $max++;
         $query = 'insert into `tiki_structures`(`parent_id`,`page_id`,`page_alias`,`pos`, `structure_id`) values(?,?,?,?,?)';
         $result = $this->query($query, array((int) $parent_id, (int) $page_id, $alias, (int) $max, (int) $structure_id));
         //Get the page_ref_id just created
         if (isset($parent_id)) {
             $parent_check = ' and `parent_id`=?';
             $attributes = array((int) $page_id, $alias, (int) $max, (int) $parent_id);
         } else {
             $parent_check = ' and (`parent_id` is null or `parent_id`=0)';
             $attributes = array((int) $page_id, $alias, (int) $max);
         }
         $query = 'select `page_ref_id` from `tiki_structures` ';
         $query .= 'where `page_id`=? and `page_alias`=? and `pos`=?';
         $query .= $parent_check;
         $ret = $this->getOne($query, $attributes);
         if (empty($parent_id)) {
             $query = 'update `tiki_structures` set `structure_id`=? where `page_ref_id`=?';
             $this->query($query, array($ret, $ret));
         }
         if ($prefs['feature_wiki_categorize_structure'] == 'y') {
             $this->categorizeNewStructurePage($name, $this->s_get_structure_info($parent_id));
         }
         if ($prefs['feature_user_watches'] == 'y') {
             include_once 'lib/notifications/notificationemaillib.php';
             sendStructureEmailNotification(array('action' => 'add', 'page_ref_id' => $ret, 'name' => $name));
         }
     }
     return $ret;
 }