Fork me on GitHub

Rapport de message :*
 

Re: Ajouter un champ au module News

Titre du sujet : Re: Ajouter un champ au module News
par irishcofee sur 30/11/2009 12:46:42

CLASS.COURSESTORY.PHP

<?php
// $Id: class.coursestory.php,v 1.29 2004/09/02 17:04:08 hthouzard Exp $
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                       <http://www.xoops.org/>   ... nbsp;   //
//  ------------------------------------------------------------------------ //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
// ------------------------------------------------------------------------- //
if (!defined('XOOPS_ROOT_PATH')) {
    die(
'XOOPS root path not defined');
}

include_once 
XOOPS_ROOT_PATH.'/class/xoopsstory.php';
include_once 
XOOPS_ROOT_PATH.'/include/comment_constants.php';
include_once 
XOOPS_ROOT_PATH.'/modules/course/include/functions.php';

//blueteen - events - begin
//transforme un tableau 2D en liste séparée par une virgule (ou le séparateur de notre choix)
function implodeArray2D ($sep$array)
{
    
$num count($array);
    
$str "";
    for (
$i 0$i $num$i++)
    {
        if (
$i)
        {
            
$str .= $sep;
        }
        
$str .= $array[$i];
    }
    return 
$str;
}

function 
stripBBCodeEvents($text_to_search) {
 
$pattern '|[[/!]*?[^[]]*?]|si';
 
$replace '';
 return 
preg_replace($pattern$replace$text_to_search);
}
//blueteen - events - end

class CourseStory extends XoopsStory
{
    var 
$coursetopic;       // XoopsTopic object
    
var $rating;        // Course rating
      
var $votes;            // Number of votes
      
var $description;    // META, desciption
      
var $keywords;        // META, keywords
      
var $topic_imgurl;
      var 
$topic_title;

    
//blueteen - events - begin
    
function setBooked($value)
    {
        
$this->booked intval($value);
    }

    function 
booked()
    {
        return 
$this->booked;
    }

    function 
setBookedend($value)
    {
        
$this->bookedend intval($value);
    }

    function 
bookedend()
    {
        return 
$this->bookedend;
    }

    function 
GetOlderRecentEvents(&$older, &$recent)
    {
        
$db =& Database::getInstance();
        
$sql 'SELECT min(booked) as minbooked, max(bookedend) as maxbookedend FROM '.$db->prefix('course_stories').' WHERE booked != 0';
        
$result $db->query($sql);
        if(!
$result) {
            
$older $recent 0;
        } else {
            list(
$older$recent) = $this->db->fetchRow($result);
        }
    }
    
//blueteen - events - end

    /**
     * Constructor
     */
    
function CourseStory($storyid=-1)
    {
        
$this->db =& Database::getInstance();
        
$this->table $this->db->prefix('course_stories');
        
$this->course_topicstable $this->db->prefix('course_topics');
        if (
is_array($storyid)) {
            
$this->makeStory($storyid);
        } elseif(
$storyid != -1) {
            
$this->getStory(intval($storyid));
        }
    }

    
/**
     * Returns the number of course_stories published before a date
     */
    
function GetCountStoriesPublishedBefore($timestamp$expired$course_topicslist='')
    {
        
$db =& Database::getInstance();
        
$sql 'SELECT count(*) as cpt FROM '.$db->prefix('course_stories').' WHERE published <=' $timestamp;
        if(
$expired) {
            
$sql .=' AND (expired>0 AND expired<='.time().')';
        }
        if(
strlen(trim($course_topicslist))>0) {
            
$sql .=' AND topicid IN ('.$course_topicslist.')';
        }
        
$result $db->query($sql);
        list(
$count) = $db->fetchRow($result);
        return 
$count;
    }


    
/**
     * Load the specified story from the database
     */
    
function getStory($storyid)
    {
        
$sql 'SELECT s.*, t.* FROM '.$this->table.' s, '.$this->db->prefix('course_topics').' t WHERE (storyid='.intval($storyid).') AND (s.topicid=t.topic_id)';
        
$array $this->db->fetchArray($this->db->query($sql));
        
$this->makeStory($array);
    }


    
/**
     * Delete course_stories that were published before a given date
     */
    
function DeleteBeforeDate($timestamp$expired$course_topicslist='')
    {
        global 
$xoopsModule;
        
$mid$xoopsModule->getVar('mid');
        
$db =& Database::getInstance();
        
$prefix $db->prefix('course_stories');
        
$vote_prefix $db->prefix('course_stories_votedata');
        
$files_prefix $db->prefix('course_stories_files');
        
$sql 'SELECT storyid FROM  '.$prefix.' WHERE published <=' $timestamp;
        if(
$expired) {
            
$sql .=' (AND expired>0 AND expired<='.time().')';
        }
        if(
strlen(trim($course_topicslist))>0) {
            
$sql .=' AND topicid IN ('.$course_topicslist.')';
        }
        
$result $db->query($sql);
        while (
$myrow $db->fetchArray($result)) {
            
xoops_comment_delete($mid$myrow['storyid']);                                    // Delete comments
            
xoops_notification_deletebyitem($mid'story'$myrow['storyid']);                // Delete notifications
            
$db->queryF('DELETE FROM '.$vote_prefix.' WHERE storyid='.$myrow['storyid']);    // Delete votes
            // Remove files and records related to the files
            
$result2 $db->query('SELECT * FROM '.$files_prefix.' WHERE storyid='.$myrow['storyid']);
            while (
$myrow2 $db->fetchArray($result2)) {
                
$name XOOPS_ROOT_PATH.'/uploads/'.$myrow2['downloadname'];
                if(
file_exists($name)) {
                    
unlink($name);
                }
                
$db->query('DELETE FROM '.$files_prefix.' WHERE fileid='.$myrow2['fileid']);
            }
            
$db->queryF('DELETE FROM '.$prefix.' WHERE storyid='.$myrow['storyid']);        // Delete the story
        
}
        return 
true;
    }

    function 
_searchPreviousOrNextArticle($storyid$next true$checkRight false)
    {
        
$db =& Database::getInstance();
        
$ret = array();
        
$storyid intval($storyid);
        if(
$next) {
            
$sql 'SELECT storyid, title FROM '.$db->prefix('course_stories').' WHERE (published > 0 AND published <= '.time().') AND (expired = 0 OR expired > '.time().') AND storyid > '.$storyid;
            
$orderBy ' ORDER BY storyid ASC';
        } else {
            
$sql 'SELECT storyid, title FROM '.$db->prefix('course_stories').' WHERE (published > 0 AND published <= '.time().') AND (expired = 0 OR expired > '.time().') AND storyid < '.$storyid;
            
$orderBy ' ORDER BY storyid DESC';
        }
        if(
$checkRight) {
            
$course_topics course_courseMygetItemIds('course_view');
            if(
count($course_topics) > 0) {
                
$sql .= ' AND topicid IN ('.implode(','$course_topics).')';
            } else {
                return 
null;
            }
        }
        
$sql .= $orderBy;
        
$db =& Database::getInstance();
        
$result $db->query($sql1);
        if(
$result) {
            
$myts =& MyTextSanitizer::getInstance();
            while ( 
$row $db->fetchArray($result) ) {
                
$ret = array('storyid' => $row['storyid'], 'title' => $myts->htmlSpecialChars($row['title']));
            }
        }
        return 
$ret;
    }

    function 
getNextArticle($storyid$checkRight=false)
    {
        return 
$this->_searchPreviousOrNextArticle($storyidtrue$checkRight);
    }

    function 
getPreviousArticle($storyid$checkRight=false)
    {
        return 
$this->_searchPreviousOrNextArticle($storyidfalse$checkRight);
    }


    
/**
      * Returns published course_stories according to some options
      */
    
function getAllPublished($limit=0$start=0$checkRight=false$topic=0$ihome=0$asobject=true$order 'published'$topic_frontpage=false)
    {
        
$db =& Database::getInstance();
        
$myts =& MyTextSanitizer::getInstance();
        
$ret = array();
        
$sql 'SELECT s.*, t.* FROM '.$db->prefix('course_stories').' s, '$db->prefix('course_topics').' t WHERE (s.published > 0 AND s.published <= '.time().') AND (s.expired = 0 OR s.expired > '.time().') AND (s.topicid=t.topic_id) ';
        if (
$topic != 0) {
            if (!
is_array($topic)) {
                if(
$checkRight) {
                    
$course_topics course_courseMygetItemIds('course_view');
                    if(!
in_array ($topic,$course_topics)) {
                        return 
null;
                    } else {
                        
$sql .= ' AND s.topicid='.intval($topic).' AND (s.ihome=1 OR s.ihome=0)';
                    }
                } else {
                    
$sql .= ' AND s.topicid='.intval($topic).' AND (s.ihome=1 OR s.ihome=0)';
                }
            } else {
                if(
$checkRight) {
                    
$course_topics course_courseMygetItemIds('course_view');
                    
$topic array_intersect($topic,$course_topics);
                }
                if(
count($topic)>0) {
                    
$sql .= ' AND s.topicid IN ('.implode(','$topic).')';
                } else {
                    return 
null;
                }
            }
        } else {
            if(
$checkRight) {
                
$course_topics course_courseMygetItemIds('course_view');
                if(
count($course_topics)>0) {
                    
$course_topics implode(','$course_topics);
                    
$sql .= ' AND s.topicid IN ('.$course_topics.')';
                } else {
                    return 
null;
                }
            }
            if (
intval($ihome) == 0) {
                
$sql .= ' AND s.ihome=0';
            }
        }
        if(
$topic_frontpage) {
            
$sql .=' AND t.topic_frontpage=1';
        }
         
$sql .= " ORDER BY s.$order DESC";
        
$result $db->query($sql,intval($limit),intval($start));

        while ( 
$myrow $db->fetchArray($result) ) {
            if (
$asobject) {
                
$ret[] = new CourseStory($myrow);
            } else {
                
$ret[$myrow['storyid']] = $myts->htmlSpecialChars($myrow['title']);
            }
        }
        return 
$ret;
    }


    
/**
     * Retourne la liste des articles aux archives (pour une période donnée)
     */
    
function getArchive($publish_start$publish_end$checkRight=false$asobject=true$order 'published')
    {
        
$db =& Database::getInstance();
        
$myts =& MyTextSanitizer::getInstance();
        
$ret = array();
        
$sql 'SELECT s.*, t.* FROM '.$db->prefix('course_stories').' s, ' .$db->prefix('course_topics').' t WHERE (s.topicid=t.topic_id) AND (s.published > ' $publish_start ' AND s.published <= ' $publish_end ') AND (expired = 0 OR expired > '.time().') ';

        if(
$checkRight) {
            
$course_topics course_courseMygetItemIds('course_view');
            if(
count($course_topics)>0) {
                
$course_topics implode(','$course_topics);
                
$sql .= ' AND topicid IN ('.$course_topics.')';
            } else {
                return 
null;
            }
        }
         
$sql .= " ORDER BY $order DESC";
        
$result $db->query($sql);
        while ( 
$myrow $db->fetchArray($result) ) {
            if (
$asobject) {
                
$ret[] = new CourseStory($myrow);
            } else {
                
$ret[$myrow['storyid']] = $myts->htmlSpecialChars($myrow['title']);
            }
        }
        return 
$ret;
    }


    
/**
     * Get the today's most readed article
     *
     * @param int         $limit            records limit
     * @param int         $start             starting record
     * @param boolean    $checkRight        Do we need to check permissions (by course_topics) ?
    * @param int         $topic             limit the job to one topic
    * @param int         $ihome             Limit to articles published in home page only ?
    * @param boolean    $asobject        Do we have to return an array of objects or a simple array ?
    * @param string        $order            Fields to sort on
     */
    
function getBigStory($limit=0$start=0$checkRight=false$topic=0$ihome=0$asobject=true$order 'counter')
    {
        
$db =& Database::getInstance();
        
$myts =& MyTextSanitizer::getInstance();
        
$ret = array();
        
$tdate mktime(0,0,0,date('n'),date('j'),date('Y'));
        
$sql 'SELECT s.*, t.* FROM '.$db->prefix('course_stories').' s, '$db->prefix('course_topics').' t WHERE (s.topicid=t.topic_id) AND (published > '.$tdate.' AND published < '.time().') AND (expired > '.time().' OR expired = 0) ';

        if ( 
intval($topic) != ) {
            if (!
is_array($topic)) {
                
$sql .= ' AND topicid='.intval($topic).' AND (ihome=1 OR ihome=0)';
            }
            else {
                if(
count($topic)>0) {
                    
$sql .= ' AND topicid IN ('.implode(','$topic).')';
                } else {
                    return 
null;
                }
            }
        } else {
            if (
$checkRight) {
                
$course_topics course_courseMygetItemIds('course_view');
                if(
count($course_topics)>0) {
                    
$course_topics implode(','$course_topics);
                    
$sql .= ' AND topicid IN ('.$course_topics.')';
                } else {
                    return 
null;
                }
            }
            if ( 
intval($ihome) == ) {
                
$sql .= ' AND ihome=0';
            }
        }
         
$sql .= " ORDER BY $order DESC";
        
$result $db->query($sql,intval($limit),intval($start));
        while ( 
$myrow $db->fetchArray($result) ) {
            if ( 
$asobject ) {
                
$ret[] = new CourseStory($myrow);
            } else {
                
$ret[$myrow['storyid']] = $myts->htmlSpecialChars($myrow['title']);
            }
        }
        return 
$ret;
    }


    
/**
    * Get all articles published by an author
    *
    * @param int $uid author's id
    * @param boolean $checkRight whether to check the user's rights to course_topics
    */
    
function getAllPublishedByAuthor($uid$checkRight=false$asobject=true)
    {
        
$db =& Database::getInstance();
        
$myts =& MyTextSanitizer::getInstance();
        
$ret = array();
        
$tblstory=$db->prefix('course_stories');
        
$tblcourse_topics=$db->prefix('course_topics');

        
$sql 'SELECT ' $tblstory '.*, '$tblcourse_topics '.topic_title, '.$tblcourse_topics.'.topic_color FROM '.$tblstory.','.$tblcourse_topics .' WHERE ('.$tblstory.'.topicid='.$tblcourse_topics.'.topic_id) AND (published > 0 AND published <= '.time().') AND (expired = 0 OR expired > '.time().')';
        
$sql .= ' AND uid='.intval($uid);
        if (
$checkRight) {
            
$course_topics course_courseMygetItemIds('course_view');
            
$course_topics implode(','$course_topics);
            if(
xoops_trim($course_topics)!='') {
                
$sql .= ' AND topicid IN ('.$course_topics.')';
            }
        }
         
$sql .= ' ORDER BY '.$tblcourse_topics.'.topic_title ASC, '.$tblstory.'.published DESC';
        
$result $db->query($sql);
        while ( 
$myrow $db->fetchArray($result) )
        {
            if ( 
$asobject ) {
                
$ret[] = new CourseStory($myrow);
            } else {
                if ( 
$myrow['nohtml'] ) {
                    
$html 0;
                } else {
                    
$html 1;
                }
                if ( 
$myrow['nosmiley'] ) {
                    
$smiley 0;
                } else {
                    
$smiley 1;
                }
                
$ret[$myrow['storyid']] = array('title'=>$myts->displayTarea($myrow['title'],$html,$smiley,1),
                                                
'topicid'=>intval($myrow['topicid']),
                                                
'storyid'=>intval($myrow['storyid']),
                                                
'hometext'=>$myts->displayTarea($myrow['hometext'],$html,$smiley,1),
                                                
'counter'=>intval($myrow['counter']),
                                                
'created'=>intval($myrow['created']),
                                                
'topic_title'=>$myts->displayTarea($myrow['topic_title'],$html,$smiley,1),
                                                
'topic_color'=>$myts->displayTarea($myrow['topic_color']),
                                                
'published'=>intval($myrow['published']),
                                                
'rating'=>(float)$myrow['rating'],
                                                
'votes'=>intval($myrow['votes']));
            }
        }
        return 
$ret;
    }


    
/**
     * Get all expired course_stories
     */
    
function getAllExpired($limit=0$start=0$topic=0$ihome=0$asobject=true)
    {
        
$db =& Database::getInstance();
        
$myts =& MyTextSanitizer::getInstance();
        
$ret = array();
        
$sql 'SELECT * FROM '.$db->prefix('course_stories').' WHERE expired <= '.time().' AND expired > 0';
        if ( !empty(
$topic) ) {
            
$sql .= ' AND topicid='.intval($topic).' AND (ihome=1 OR ihome=0)';
        } else {
            if ( 
intval($ihome) == ) {
                
$sql .= ' AND ihome=0';
            }
        }

         
$sql .= ' ORDER BY expired DESC';
        
$result $db->query($sql,intval($limit),intval($start));
        while ( 
$myrow $db->fetchArray($result) ) {
            if (
$asobject) {
                
$ret[] = new CourseStory($myrow);
            } else {
                
$ret[$myrow['storyid']] = $myts->htmlSpecialChars($myrow['title']);
            }
        }
        return 
$ret;
    }



    
/**
     * Returns an array of object containing all the course to be automatically published.
     */
    
function getAllAutoStory($limit=0$asobject=true$start=0)
    {
        
$db =& Database::getInstance();
        
$myts =& MyTextSanitizer::getInstance();
        
$ret = array();
        
$sql 'SELECT * FROM '.$db->prefix('course_stories').' WHERE published > '.time().' ORDER BY published ASC';
        
$result $db->query($sql,intval($limit),intval($start));
        while ( 
$myrow $db->fetchArray($result) ) {
            if ( 
$asobject ) {
                
$ret[] = new CourseStory($myrow);
            } else {
                
$ret[$myrow['storyid']] = $myts->htmlSpecialChars($myrow['title']);
            }
        }
        return 
$ret;
    }

    
/**
    * Get all submitted course_stories awaiting approval
    *
    * @param int $limit Denotes where to start the query
    * @param boolean $asobject true will returns the course_stories as an array of objects, false will return storyid => title
    * @param boolean $checkRight whether to check the user's rights to course_topics
    */
    
function getAllSubmitted($limit=0$asobject=true$checkRight false$start=0)
    {
        
$db =& Database::getInstance();
        
$myts =& MyTextSanitizer::getInstance();
        
$ret = array();
        
$criteria = new CriteriaCompo(new Criteria('published'0));
        if (
$checkRight) {
            global 
$xoopsUser;
            if (!
is_object($xoopsUser)) {
                return 
$ret;
            }
            
$allowedcourse_topics course_courseMygetItemIds('course_approve');
            
$criteria2 = new CriteriaCompo();
            foreach (
$allowedcourse_topics as $key => $topicid) {
                
$criteria2->add(new Criteria('topicid'$topicid), 'OR');
            }
            
$criteria->add($criteria2);
        }
        
$sql 'SELECT s.*, t.* FROM '.$db->prefix('course_stories').' s, '.$db->prefix('course_topics').' t ';
        
$sql .= ' '.$criteria->renderWhere().' AND (s.topicid=t.topic_id) ORDER BY created DESC';
        
$result $db->query($sql,intval($limit),intval($start));
        while ( 
$myrow $db->fetchArray($result) ) {
            if ( 
$asobject ) {
                
$ret[] = new CourseStory($myrow);
            } else {
                
$ret[$myrow['storyid']] = $myts->htmlSpecialChars($myrow['title']);
            }
        }
        return 
$ret;
    }


    
/**
     * Used in the module's admin to know the number of expired, automated or pubilshed course
     *
       * @param int    $storytype    1=Expired, 2=Automated, 3=New submissions, 4=Last published course_stories
       * @param bool    $checkRight    verify permissions or not ?
     */
    
function getAllStoriesCount($storytype=1$checkRight false)
    {
        
$db =& Database::getInstance();
        
$sql 'SELECT count(*) as cpt FROM '.$db->prefix('course_stories').' WHERE ';
        switch(
$storytype) {
            case 
1:    // Expired
                
$sql .='(expired <= '.time().' AND expired >0)';
                break;
            case 
2:    // Automated
                
$sql .='(published > '.time().')';
                break;
            case 
3:    // New submissions
                
$sql .='(published = 0)';
                break;
            case 
4:    // Last published course_stories
                
$sql .='(published > 0 AND published <= '.time().') AND (expired = 0 OR expired > '.time().')';
                break;
        }
        if(
$checkRight) {
            
$course_topics course_courseMygetItemIds('course_view');
            if(
count($course_topics)>0) {
                
$course_topics implode(','$course_topics);
                
$sql .= ' AND topicid IN ('.$course_topics.')';
            } else {
                return 
0;
            }
        }
        
$result $db->query($sql);
        
$myrow $db->fetchArray($result);
        return 
$myrow['cpt'];
    }


    
/**
     * Get a list of course_stories (as objects) related to a specific topic
     */
    
function getByTopic($topicid$limit=0)
    {
        
$ret = array();
        
$db =& Database::getInstance();
        
$sql 'SELECT * FROM '.$db->prefix('course_stories').' WHERE topicid='.intval($topicid).' ORDER BY published DESC';
        
$result $db->query($sqlintval($limit), 0);
        while( 
$myrow $db->fetchArray($result) ){
            
$ret[] = new CourseStory($myrow);
        }
        return 
$ret;
    }


    
/**
     * Count the number of course published for a specific topic
     */
    
function countPublishedByTopic($topicid=0$checkRight false)
    {
        
$db =& Database::getInstance();
        
$sql 'SELECT COUNT(*) FROM '.$db->prefix('course_stories').' WHERE published > 0 AND published <= '.time().' AND (expired = 0 OR expired > '.time().')';
        if ( !empty(
$topicid) ) {
            
$sql .= ' AND topicid='.intval($topicid);
        } else {
            
$sql .= ' AND ihome=0';
            if (
$checkRight) {
                
$course_topics course_courseMygetItemIds('course_view');
                if(
count($course_topics)>0) {
                    
$course_topics implode(','$course_topics);
                    
$sql .= ' AND topicid IN ('.$course_topics.')';
                } else {
                    return 
null;
                }
            }
        }
        
$result $db->query($sql);
        list(
$count) = $db->fetchRow($result);
        return 
$count;
    }


    
/**
     * Internal function
     */
    
function adminlink()
    {
        
$ret "&nbsp;[ <a href='".XOOPS_URL."/modules/course/submit.php?op=edit&amp;storyid=".$this->storyid()."'>"._EDIT."</a> | <a href='".XOOPS_URL."/modules/course/admin/index.php?op=delete&amp;storyid=".$this->storyid()."'>"._DELETE."</a> ]&nbsp;";
        return 
$ret;
    }


    
/**
     * Get the topic image url
     */
    
function topic_imgurl($format='S')
    {
        if(
trim($this->topic_imgurl)=='') {
            
$this->topic_imgurl='blank.png';
        }
        
$myts =& MyTextSanitizer::getInstance();
        switch(
$format){
            case 
'S':
                
$imgurl$myts->htmlSpecialChars($this->topic_imgurl);
                break;
            case 
'E':
                
$imgurl $myts->htmlSpecialChars($this->topic_imgurl);
                break;
            case 
'P':
                
$imgurl $myts->stripSlashesGPC($this->topic_imgurl);
                
$imgurl $myts->htmlSpecialChars($imgurl);
                break;
            case 
'F':
                
$imgurl $myts->stripSlashesGPC($this->topic_imgurl);
                
$imgurl $myts->htmlSpecialChars($imgurl);
                break;
        }
        return 
$imgurl;
    }

    function 
topic_title($format='S')
    {
        
$myts =& MyTextSanitizer::getInstance();
        switch(
$format){
            case 
'S':
                
$title $myts->htmlSpecialChars($this->topic_title);
                break;
            case 
'E':
                
$title $myts->htmlSpecialChars($this->topic_title);
                break;
            case 
'P':
                
$title $myts->stripSlashesGPC($this->topic_title);
                
$title $myts->htmlSpecialChars($title);
                break;
            case 
'F':
                
$title $myts->stripSlashesGPC($this->topic_title);
                
$title $myts->htmlSpecialChars($title);
                break;
        }
        return 
$title;
    }

    function 
imglink()
    {
        
$ret '';
        if (
$this->topic_imgurl() != '' && file_exists(XOOPS_ROOT_PATH.'/modules/course/images/course_topics/'.$this->topic_imgurl())) {
            
$ret "<a href='".XOOPS_URL."/modules/course/index.php?storytopic=".$this->topicid()."'><img src='".XOOPS_URL."/modules/course/images/course_topics/".$this->topic_imgurl()."' alt='".$this->topic_title()."' hspace='10' vspace='10' align='".$this->topicalign()."' /></a>";
        }
        return 
$ret;
    }

    function 
textlink()
    {
        
$ret "<a href='".XOOPS_URL."/modules/course/index.php?storytopic=".$this->topicid()."'>".$this->topic_title()."</a>";
        return 
$ret;
    }

    
/**
     * Function used to prepare an article to be showned
     */
    
function prepare2show($filescount)
    {
        include_once 
XOOPS_ROOT_PATH.'/modules/course/include/functions.php';
        global 
$xoopsUser$xoopsConfig$xoopsModuleConfig;
        
$myts =& MyTextSanitizer::getInstance();
        
$infotips course_coursegetmoduleoption('infotips');
        
$story = array();
        
$story['id'] = $this->storyid();
        
$story['poster'] = $this->uname();
        
$story['author_name'] = $this->uname();
        
$story['author_uid'] = $this->uid();
        if ( 
$story['poster'] != false ) {
            
$story['poster'] = "<a href='".XOOPS_URL."/userinfo.php?uid=".$this->uid()."'>".$story['poster']."</a>";
        } else {
            if(
$xoopsModuleConfig['displayname']!=3) {
                
$story['poster'] = $xoopsConfig['anonymous'];
            }
        }
        if (
$xoopsModuleConfig['ratecourse']) {
            
$story['rating'] = number_format($this->rating(), 2);
            if (
$this->votes == 1) {
                
$story['votes'] = _NW_ONEVOTE;
            } else {
                
$story['votes'] = sprintf(_NW_NUMVOTES,$this->votes);
            }
        }
        
$story['posttimestamp'] = $this->published();
        
$story['posttime'] = formatTimestamp($story['posttimestamp'],course_coursegetmoduleoption('dateformat'));
        
$story['topic_description'] = $myts->displayTarea($this->topic_description);

        
$auto_summary '';
        
$tmp '';
        
$auto_summary $this->auto_summary($this->bodytext(),$tmp);

        
$story['text'] = $this->hometext();
        
$story['text'] = str_replace('[summary]'$auto_summary$story['text']);

        
$introcount strlen($story['text']);
        
$fullcount strlen($this->bodytext());
        
$totalcount $introcount $fullcount;

        
$morelink '';
        if ( 
$fullcount ) {
            
$morelink .= '<a href="'.XOOPS_URL.'/modules/course/article.php?storyid='.$this->storyid().'';
            
$morelink .= '">'._NW_READMORE.'</a>';
            
$morelink .= ' | '.sprintf(_NW_BYTESMORE,$totalcount);
            if (
XOOPS_COMMENT_APPROVENONE != $xoopsModuleConfig['com_rule']) {
                
$morelink .= ' | ';
            }
        }
        if (
XOOPS_COMMENT_APPROVENONE != $xoopsModuleConfig['com_rule']) {
            
$ccount $this->comments();
            
$morelink .= '<a href="'.XOOPS_URL.'/modules/course/article.php?storyid='.$this->storyid().'';
            
$morelink2 '<a href="'.XOOPS_URL.'/modules/course/article.php?storyid='.$this->storyid().'';
            if ( 
$ccount == ) {
                
$morelink .= '">'._NW_COMMENTS.'</a>';
            } else {
                if ( 
$fullcount ) {
                    if ( 
$ccount == ) {
                        
$morelink .= '">'._NW_READMORE.'</a> | '.$morelink2.'">'._NW_ONECOMMENT.'</a>';
                    } else {
                        
$morelink .= '">'._NW_READMORE.'</a> | '.$morelink2.'">';
                        
$morelink .= sprintf(_NW_NUMCOMMENTS$ccount);
                        
$morelink .= '</a>';
                    }
                } else {
                    if ( 
$ccount == ) {
                        
$morelink .= '">'._NW_ONECOMMENT.'</a>';
                    } else {
                        
$morelink .= '">';
                        
$morelink .= sprintf(_NW_NUMCOMMENTS$ccount);
                        
$morelink .= '</a>';
                    }
                }
            }
        }
        
$story['morelink'] = $morelink;
        
$story['adminlink'] = '';

        
$approveprivilege 0;
        if(
course_courseis_admin_group()) {
            
$approveprivilege 1;
        }

        if(
$xoopsModuleConfig['authoredit']==&& (is_object($xoopsUser) && $xoopsUser->getVar('uid')==$this->uid())) {
            
$approveprivilege 1;
        }
        if (
$approveprivilege) {
            
$story['adminlink'] = $this->adminlink();
        }
        
$story['mail_link'] = 'mailto:?subject='.sprintf(_NW_INTARTICLE,$xoopsConfig['sitename']).'&amp;body='.sprintf(_NW_INTARTFOUND$xoopsConfig['sitename']).':  '.XOOPS_URL.'/modules/course/article.php?storyid='.$this->storyid();
        
$story['imglink'] = '';
        
$story['align'] = '';
        if ( 
$this->topicdisplay() ) {
            
$story['imglink'] = $this->imglink();
            
$story['align'] = $this->topicalign();
        }
        if(
$infotips>0) {
            
$story['infotips'] = ' title="'.course_coursemake_infotips($this->hometext()).'"';
        } else {
            
$story['infotips'] = '';
        }
        
$story['title'] = "<a href='".XOOPS_URL."/modules/course/article.php?storyid=".$this->storyid()."'".$story['infotips'].">".$this->title()."</a>";

        
$story['hits'] = $this->counter();
        if(
$filescount>0) {
            
$story['files_attached']= true;
            
$story['attached_link']="<a href='".XOOPS_URL.'/modules/course/article.php?storyid='.$this->storyid()."' title='"._NW_ATTACHEDLIB."'><img src='".XOOPS_URL.'/modules/course/images/attach.gif'."' title='"._NW_ATTACHEDLIB."'></a>";
        } else {
            
$story['files_attached']= false;
            
$story['attached_link']='';
        }
        return 
$story;
    }

    
/**
     * Returns the user's name of the current story according to the module's option "displayname"
     */
    
function uname($uid=0)
    {
        global 
$xoopsConfig;
        include_once 
XOOPS_ROOT_PATH.'/modules/course/include/functions.php';
        static 
$tblusers = array();
        
$option=-1;
        if(
$uid == 0) {
            
$uid=$this->uid();
        }

        if(
is_array($tblusers) && array_key_exists($uid,$tblusers)) {
            return     
$tblusers[$uid];
        }

        
$option course_coursegetmoduleoption('displayname');
        if (!
$option) {
            
$option=1;
        }

        switch(
$option) {
            case 
1:        // Username
                
$tblusers[$uid]=XoopsUser::getUnameFromId($uid);
                return 
$tblusers[$uid];

            case 
2:        // Display full name (if it is not empty)
                
$member_handler =& xoops_gethandler('member');
                
$thisuser $member_handler->getUser($uid);
                if (
is_object($thisuser)) {
                    
$return $thisuser->getVar('name');
                    if (
$return == '') {
                        
$return=$thisuser->getVar('uname');
                    }
                } else {
                    
$return=$xoopsConfig['anonymous'];
                }
                
$tblusers[$uid]=$return;
                return 
$return;

            case 
3:        // Nothing
                
$tblusers[$uid]='';
                return 
'';
        }
    }

    
/**
    * Function used to export course (in xml) and eventually the course_topics definitions
    * Warning, permissions are not exported !
    * @param int         $fromdate         Starting date
    * @param int         $todate         Ending date
    * @param string        $topiclist        If not empty, a list of course_topics to limit to
    * @param boolean    $usecourse_topicsdef     Should we also export course_topics definitions ?
    * @param boolean    $asobject        Return values as an object or not ?
    */
    
function CourseExport($fromdate$todate$course_topicslist=''$usecourse_topicsdef=0, &$tblcourse_topics$asobject=true$order 'published')
    {
        
$ret=Array();
        
$myts =& MyTextSanitizer::getInstance();
        if(
$usecourse_topicsdef) {    // We firt begin by exporting course_topics definitions
            // Before all we must know wich course_topics to export
            
$sql 'SELECT distinct topicid FROM '.$this->db->prefix('course_stories').' WHERE (published >=' $fromdate ' AND published <= ' $todate .')';
            if(
strlen(trim($course_topicslist))>0) {
                
$sql .=' AND topicid IN ('.$course_topicslist.')';
            }
            
$result $this->db->query($sql);
            while ( 
$myrow $this->db->fetchArray($result) ) {
                
$tblcourse_topics[]=$myrow['topicid'];
            }
        }

        
// Now we can search for the course_stories
        
$sql 'SELECT s.*, t.* FROM '.$this->table.' s, '.$this->db->prefix('course_topics').' t WHERE (s.topicid=t.topic_id) AND (s.published >=' $fromdate ' AND s.published <= ' $todate .')';
        if(
strlen(trim($course_topicslist))>0) {
            
$sql .=' AND topicid IN ('.$course_topicslist.')';
        }
        
$sql .= " ORDER BY $order DESC";
        
$result $this->db->query($sql);
        while (
$myrow $this->db->fetchArray($result)) {
            if (
$asobject) {
                
$ret[] = new CourseStory($myrow);
            } else {
                
$ret[$myrow['storyid']] = $myts->htmlSpecialChars($myrow['title']);
            }
        }
        return 
$ret;
    }


    
/**
     * Create or update an article
     */
    
function store($approved=false)
    {
        
$myts =& MyTextSanitizer::getInstance();
        
$counter = isset($this->counter) ? $this->counter 0;
        
$title =$myts->censorString($this->title);
        
$title $myts->addSlashes($title);
        
//ajout irishcofee
        
$price $myts->censorString($this->price);
        
//fin ajout irishcofee
        
$hostname=$myts->addSlashes($this->hostname);
        
$type=$myts->addSlashes($this->type);
        
$hometext =$myts->addSlashes($myts->censorString($this->hometext));
        
$bodytext =$myts->addSlashes($myts->censorString($this->bodytext));
        
$description =$myts->addSlashes($myts->censorString($this->description));
        
$keywords =$myts->addSlashes($myts->censorString($this->keywords));
        
$votesintval($this->votes);
        
$rating = (float)($this->rating);
        if (!isset(
$this->nohtml) || $this->nohtml != 1) {
            
$this->nohtml 0;
        }
        if (!isset(
$this->nosmiley) || $this->nosmiley != 1) {
            
$this->nosmiley 0;
        }
        if (!isset(
$this->notifypub) || $this->notifypub != 1) {
            
$this->notifypub 0;
        }
        if(!isset(
$this->topicdisplay) || $this->topicdisplay != 0) {
            
$this->topicdisplay 1;
        }
        
$expired = !empty($this->expired) ? $this->expired 0;
        
$booked = !empty($this->booked) ? $this->booked 0;//blueteen - events - date de début
        
$bookedend = !empty($this->bookedend) ? $this->bookedend 0;//blueteen - events - date de fin

        
if (!isset($this->storyid)) {
            
//$newpost = 1;
            
$coursetoryid $this->db->genId($this->table.'_storyid_seq');
            
$created time();
            
$published = ( $this->approved ) ? intval($this->published) : 0;
            
$sql sprintf("INSERT INTO %s (storyid, uid, title, created, published, expired, hostname, nohtml, nosmiley, hometext, bodytext, counter, topicid, ihome, notifypub, story_type, topicdisplay, topicalign, comments, rating, votes, description, keywords, booked, bookedend, price) VALUES (%u, %u, '%s', %u, %u, %u, '%s', %u, %u, '%s', '%s', %u, %u, %u, %u, '%s', %u, '%s', %u, %u, %u, '%s', '%s', %u, %u, %s)"$this->table$coursetoryidintval($this->uid()), $title$created$published$expired$hostnameintval($this->nohtml()), intval($this->nosmiley()), $hometext$bodytext$counterintval($this->topicid()), intval($this->ihome()), intval($this->notifypub()), $typeintval($this->topicdisplay()), $this->topicalignintval($this->comments()), $rating$votes$description$keywords$booked$bookedend$price);//blueteen - events - ajout base de données ajout rishcofee
        
} else {
            
$sql sprintf("UPDATE %s SET title='%s', published=%u, expired=%u, nohtml=%u, nosmiley=%u, hometext='%s', bodytext='%s', topicid=%u, ihome=%u, topicdisplay=%u, topicalign='%s', comments=%u, rating=%u, votes=%u, uid=%u, description='%s', keywords='%s',  booked='%u', bookedend='%u', price='%s' WHERE storyid = %u"$this->table$titleintval($this->published()), $expiredintval($this->nohtml()), intval($this->nosmiley()), $hometext$bodytextintval($this->topicid()), intval($this->ihome()), intval($this->topicdisplay()), $this->topicalignintval($this->comments()), $rating$votesintval($this->uid()), $description$keywords$booked$bookedend$priceintval($this->storyid()));//blueteen - events - mise à jour base de données ajout irishcofee
            
$coursetoryid intval($this->storyid());
        }
        if (!
$this->db->queryF($sql)) {
            return 
false;
        }
        if (empty(
$coursetoryid)) {
            
$coursetoryid $this->db->getInsertId();
            
$this->storyid $coursetoryid;
        }
        return 
$coursetoryid;
    }

    function 
rating()
    {
        return 
$this->rating;
    }

    function 
votes()
    {
        return 
$this->votes;
    }

    function 
Setdescription($data)
    {
        
$this->description=$data;
    }

    function 
Setkeywords($data)
    {
        
$this->keywords=$data;
    }

    function 
description($format='S')
    {
        
$myts =& MyTextSanitizer::getInstance();
        switch(
strtoupper($format)) {
            case 
'S':
                
$description$myts->htmlSpecialChars($this->description);
                break;
            case 
'P':
            case 
'F':
                
$description $myts->htmlSpecialChars($myts->stripSlashesGPC($this->description));
                break;
            case 
'E':
                
$description $myts->htmlSpecialChars($this->description);
                break;
        }
        return 
$description;
    }

    function 
keywords($format='S')
    {
        
$myts =& MyTextSanitizer::getInstance();
        switch(
strtoupper($format)) {
            case 
'S':
                
$keywords$myts->htmlSpecialChars($this->keywords);
                break;
            case 
'P':
            case 
'F':
                
$keywords $myts->htmlSpecialChars($myts->stripSlashesGPC($this->keywords));
                break;
            case 
'E':
                
$keywords $myts->htmlSpecialChars($this->keywords);
                break;
        }
        return 
$keywords;
    }

    
/**
     * Returns a random number of course
     */
    
function getRandomCourse($limit=0$start=0$checkRight=false$topic=0$ihome=0$order='published'$topic_frontpage=false)
    {
        
$db =& Database::getInstance();
        
$ret $rand_keys $ret3 = array();
        
$sql 'SELECT storyid FROM '.$db->prefix('course_stories').' WHERE (published > 0 AND published <= '.time().') AND (expired = 0 OR expired > '.time().')';
        if (
$topic != 0) {
            if (!
is_array($topic)) {
                if(
$checkRight) {
                    
$course_topics course_courseMygetItemIds('course_view');
                    if(!
in_array ($topic,$course_topics)) {
                        return 
null;
                    } else {
                        
$sql .= ' AND topicid='.intval($topic).' AND (ihome=1 OR ihome=0)';
                    }
                } else {
                    
$sql .= ' AND topicid='.intval($topic).' AND (ihome=1 OR ihome=0)';
                }
            } else {
                if(
count($topic)>0) {
                    
$sql .= ' AND topicid IN ('.implode(','$topic).')';
                } else {
                    return 
null;
                }
            }
        } else {
            if(
$checkRight) {
                
$course_topics course_courseMygetItemIds('course_view');
                if(
count($course_topics)>0) {
                    
$course_topics implode(','$course_topics);
                    
$sql .= ' AND topicid IN ('.$course_topics.')';
                } else {
                    return 
null;
                }
            }
            if (
intval($ihome) == 0) {
                
$sql .= ' AND ihome=0';
            }
        }
        if(
$topic_frontpage) {
            
$sql .=' AND t.topic_frontpage=1';
        }
         
$sql .= " ORDER BY $order DESC";
        
$result $db->query($sql);

        while ( 
$myrow $db->fetchArray($result) ) {
            
$ret[] = $myrow['storyid'];
        }
        
$cnt=count($ret);
        if(
$cnt)    {
            
srand ((double) microtime() * 10000000);
            if(
$limit>$cnt) {
                
$limit=$cnt;
            }
            
$rand_keys array_rand($ret$limit);
            if(
$limit>1) {
                for(
$i=0;$i<$limit;$i++) {
                    
$onestory=$ret[$rand_keys[$i]];
                    
$ret3[]= new CourseStory($onestory);
                }
            } else {
                
$ret3[]= new CourseStory($ret[$rand_keys]);
            }
        }
        return 
$ret3;
    }



    
/**
     * Returns statistics about the course_stories and course_topics
     */
    
function GetStats($limit)
    {
        
$ret=array();
        
$db =& Database::getInstance();
        
$tbls=$db->prefix('course_stories');
        
$tblt=$db->prefix('course_topics');
        
$tblf=$db->prefix('course_stories_files');

        
$db =& Database::getInstance();
        
// Number of course_stories per topic, including expired and non published course_stories
        
$ret2=array();
        
$sql="SELECT count(s.storyid) as cpt, s.topicid, t.topic_title FROM $tbls s, $tblt t WHERE s.topicid=t.topic_id GROUP BY s.topicid ORDER BY t.topic_title";
        
$result $db->query($sql);
        while (
$myrow $db->fetchArray($result) ) {
            
$ret2[$myrow['topicid']]=$myrow;
        }
        
$ret['course_storiespertopic']=$ret2;
        unset(
$ret2);

        
// Total of reads per topic
        
$ret2=array();
        
$sql="SELECT Sum(counter) as cpt, topicid FROM $tbls GROUP BY topicid ORDER BY topicid";
        
$result $db->query($sql);
        while (
$myrow $db->fetchArray($result) ) {
            
$ret2[$myrow['topicid']]=$myrow['cpt'];
        }
        
$ret['readspertopic']=$ret2;
        unset(
$ret2);

        
// Attached files per topic
        
$ret2=array();
        
$sql="SELECT Count(*) as cpt, s.topicid FROM $tblf f, $tbls s WHERE f.storyid=s.storyid GROUP BY s.topicid ORDER BY s.topicid";
        
$result $db->query($sql);
        while (
$myrow $db->fetchArray($result) ) {
            
$ret2[$myrow['topicid']]=$myrow['cpt'];
        }
        
$ret['filespertopic']=$ret2;
        unset(
$ret2);

        
// Expired articles per topic
        
$ret2=array();
        
$sql="SELECT Count(storyid) as cpt, topicid FROM $tbls WHERE expired>0 AND expired<=".time()." GROUP BY topicid ORDER BY topicid";
        
$result $db->query($sql);
        while (
$myrow $db->fetchArray($result) ) {
            
$ret2[$myrow['topicid']]=$myrow['cpt'];
        }
        
$ret['expiredpertopic']=$ret2;
        unset(
$ret2);

        
// Number of unique authors per topic
        
$ret2=array();
        
$sql="SELECT Count(Distinct(uid)) as cpt, topicid FROM $tbls GROUP BY topicid ORDER BY topicid";
        
$result $db->query($sql);
        while (
$myrow $db->fetchArray($result) ) {
            
$ret2[$myrow['topicid']]=$myrow['cpt'];
        }
        
$ret['authorspertopic']=$ret2;
        unset(
$ret2);

        
// Most readed articles
        
$ret2=array();
        
$sql="SELECT s.storyid, s.uid, s.title, s.counter, s.topicid, t.topic_title  FROM $tbls s, $tblt t WHERE s.topicid=t.topic_id ORDER BY s.counter DESC";
        
$result $db->query($sql,intval($limit));
        while (
$myrow $db->fetchArray($result) ) {
            
$ret2[$myrow['storyid']]=$myrow;
        }
        
$ret['mostreadedcourse']=$ret2;
        unset(
$ret2);


        
// Less readed articles
        
$ret2=array();
        
$sql="SELECT s.storyid, s.uid, s.title, s.counter, s.topicid, t.topic_title  FROM $tbls s, $tblt t WHERE s.topicid=t.topic_id ORDER BY s.counter";
        
$result $db->query($sql,intval($limit));
        while (
$myrow $db->fetchArray($result) ) {
            
$ret2[$myrow['storyid']]=$myrow;
        }
        
$ret['lessreadedcourse']=$ret2;
        unset(
$ret2);

        
// Best rated articles
        
$ret2=array();
        
$sql="SELECT s.storyid, s.uid, s.title, s.rating, s.topicid, t.topic_title  FROM $tbls s, $tblt t WHERE s.topicid=t.topic_id ORDER BY s.rating DESC";
        
$result $db->query($sql,intval($limit));
        while (
$myrow $db->fetchArray($result) ) {
            
$ret2[$myrow['storyid']]=$myrow;
        }
        
$ret['besratedcourse']=$ret2;
        unset(
$ret2);

        
// Most readed authors
        
$ret2=array();
        
$sql="SELECT Sum(counter) as cpt, uid FROM $tbls GROUP BY uid ORDER BY cpt DESC";
        
$result $db->query($sql,intval($limit));
        while (
$myrow $db->fetchArray($result) ) {
            
$ret2[$myrow['uid']]=$myrow['cpt'];
        }
        
$ret['mostreadedauthors']=$ret2;
        unset(
$ret2);

        
// Best rated authors
        
$ret2=array();
        
$sql="SELECT Avg(rating) as cpt, uid FROM $tbls WHERE votes > 0 GROUP BY uid ORDER BY cpt DESC";
        
$result $db->query($sql,intval($limit));
        while (
$myrow $db->fetchArray($result) ) {
            
$ret2[$myrow['uid']]=$myrow['cpt'];
        }
        
$ret['bestratedauthors']=$ret2;
        unset(
$ret2);

        
// Biggest contributors
        
$ret2=array();
        
$sql="SELECT Count(*) as cpt, uid FROM $tbls GROUP BY uid ORDER BY cpt DESC";
        
$result $db->query($sql,intval($limit));
        while (
$myrow $db->fetchArray($result) ) {
            
$ret2[$myrow['uid']]=$myrow['cpt'];
        }
        
$ret['biggestcontributors']=$ret2;
        unset(
$ret2);

        return 
$ret;
    }


    
/**
     * Get the date of the older and most recent course
     */
    
function GetOlderRecentCourse(&$older, &$recent)
    {
        
$db =& Database::getInstance();
        
$sql 'SELECT min(published) as minpublish, max(published) as maxpublish FROM '.$db->prefix('course_stories');
        
$result $db->query($sql);
        if(!
$result) {
            
$older $recent 0;
        } else {
            list(
$older$recent) = $this->db->fetchRow($result);
        }
    }
    
    
/*
     * Returns the author's IDs for the Who's who page
     */
    
function getWhosWho($checkRight=false$limit=0$start=0)
    {
        
$db =& Database::getInstance();
        
$ret = array();
        
$sql 'SELECT distinct(uid) as uid FROM '.$db->prefix('course_stories').' WHERE (published > 0 AND published <= '.time().') AND (expired = 0 OR expired > '.time().')';
        if(
$checkRight) {
            
$course_topics course_courseMygetItemIds('course_view');
            if(
count($course_topics)>0) {
                
$course_topics implode(','$course_topics);
                
$sql .= ' AND topicid IN ('.$course_topics.')';
            } else {
                return 
null;
            }
        }
         
$sql .= " ORDER BY uid";
        
$result $db->query($sql);
        while ( 
$myrow $db->fetchArray($result) ) {
            
$ret[] = $myrow['uid'];
        }
        return 
$ret;
    }


    
/**
     * Returns the content of the summary and the titles requires for the list selector
     */
    
function auto_summary($text, &$titles)
    {
        
$auto_summary '';
        if(
course_coursegetmoduleoption('enhanced_pagenav')) {
            
$expr_matches = array();
            
$posdeb preg_match_all('/([pagebreak:|[pagebreak).*]/iU'$text$expr_matches);
            if(
count($expr_matches) > 0) {
                
$delimiters $expr_matches[0];
                
$arr_search = array('[pagebreak:''[pagebreak'']');
                
$arr_replace = array('''''');
                
$cpt 1;
                if(isset(
$titles) && is_array($titles)) {
                    
$titles[] = strip_tags(sprintf(_NW_PAGE_AUTO_SUMMARY,1$this->title()));
                }
                
$item "<a href='".XOOPS_URL.'/modules/course/article.php?storyid='.$this->storyid()."&page=0'>".sprintf(_NW_PAGE_AUTO_SUMMARY,1$this->title()).'</a><br />';
                
$auto_summary .= $item;

                foreach(
$delimiters as $item) {
                    
$cpt++;
                    
$item str_replace($arr_search$arr_replace$item);
                    if(
xoops_trim($item) == '') {
                        
$item $cpt;
                    }
                    
$titles[] = strip_tags(sprintf(_NW_PAGE_AUTO_SUMMARY,$cpt$item));
                    
$item "<a href='".XOOPS_URL.'/modules/course/article.php?storyid='.$this->storyid().'&page='.($cpt-1)."'>".sprintf(_NW_PAGE_AUTO_SUMMARY,$cpt$item).'</a><br />';
                    
$auto_summary .= $item;
                }
            }
        }
        return 
$auto_summary;
    }

    function 
hometext($format 'Show')
    {
        
$myts =& MyTextSanitizer::getInstance();
        
$html $smiley $xcodes 1;
        if ( 
$this->nohtml() ) {
            
$html 0;
        }
        if ( 
$this->nosmiley() ) {
            
$smiley 0;
        }
        switch ( 
$format ) {
        case 
'Show':
            
$hometext $myts->displayTarea($this->hometext,$html,$smiley,$xcodes);
            
$tmp '';
            
$auto_summary $this->auto_summary($this->bodytext('Show'),$tmp);
            
$hometext str_replace('[summary]'$auto_summary$hometext);
            break;
        case 
'Edit':
            
$hometext $myts->htmlSpecialChars($this->hometext);
            break;
        case 
'Preview':
            
$hometext $myts->previewTarea($this->hometext,$html,$smiley,$xcodes);
            break;
        case 
'InForm':
            
$hometext $myts->stripSlashesGPC($this->hometext);
            
$hometext $myts->htmlSpecialChars($hometext);
            break;
        }
        return 
$hometext;
    }

    function 
bodytext($format 'Show')
    {
        
$myts =& MyTextSanitizer::getInstance();
        
$html 1;
        
$smiley 1;
        
$xcodes 1;
        if ( 
$this->nohtml() ) {
            
$html 0;
        }
        if ( 
$this->nosmiley() ) {
            
$smiley 0;
        }
        switch ( 
$format ) {
        case 
'Show':
            
$bodytext $myts->displayTarea($this->bodytext,$html,$smiley,$xcodes);
            
$tmp '';
            
$auto_summary $this->auto_summary($bodytext,$tmp);
            
$bodytext str_replace('[summary]'$auto_summary$bodytext);
            break;
        case 
'Edit':
            
$bodytext $myts->htmlSpecialChars($this->bodytext);
            break;
        case 
'Preview':
            
$bodytext $myts->previewTarea($this->bodytext,$html,$smiley$xcodes);
            break;
        case 
'InForm':
            
$bodytext $myts->stripSlashesGPC($this->bodytext);
            
$bodytext $myts->htmlSpecialChars($bodytext);
            break;
        }
        return 
$bodytext;
    }

    
/**
      * Returns course_stories by Ids
      */
    
function getStoriesByIds($ids$checkRight true$asobject true$order 'published'$onlyOnline true)
    {
        
$limit $start 0;
        
$db =& Database::getInstance();
        
$myts =& MyTextSanitizer::getInstance();
        
$ret = array();
        
$sql 'SELECT s.*, t.* FROM '.$db->prefix('course_stories').' s, '$db->prefix('course_topics').' t WHERE ';
        if(
is_array($ids) && count($ids) > 0) {
            
array_walk($ids'intval');
        }
        
$sql .= ' s.storyid IN ('.implode(','$ids).') ';

        if(
$onlyOnline) {
            
$sql .= ' AND (s.published > 0 AND s.published <= '.time().') AND (s.expired = 0 OR s.expired > '.time().') ';
        }
        
$sql .= ' AND (s.topicid=t.topic_id) ';
        if(
$checkRight) {
            
$course_topics course_courseMygetItemIds('course_view');
            if(
count($course_topics)>0) {
                
$course_topics implode(','$course_topics);
                
$sql .= ' AND s.topicid IN ('.$course_topics.')';
            } else {
                return 
null;
            }
        }
         
$sql .= " ORDER BY s.$order DESC";
        
$result $db->query($sql,intval($limit),intval($start));

        while ( 
$myrow $db->fetchArray($result) ) {
            if (
$asobject) {
                
$ret[$myrow['storyid']] = new CourseStory($myrow);
            } else {
                
$ret[$myrow['storyid']] = $myts->htmlSpecialChars($myrow['title']);
            }
        }
        return 
$ret;
    }

}
?>

Propulsé avec XOOPS | Graphisme adapté par Tatane, Grosdunord, Montuy337513

90 Personne(s) en ligne (68 Personne(s) connectée(s) sur Forum) | Utilisateur(s): 0 | Invité(s): 90 | Plus ...