Fork me on GitHub




(1) 2 »


Ajouter un champ au module News
Régulier
Inscrit: 22/03/2006 10:49
Messages: 197
Bonjour,

je cherche à ajouter un champ au module news 1.63.
apres plusieurs essais, je n'arrive pas à faire en sorte que la valeur du nouveau champ soit stockée dans la BDD.

En partant de zero, est ce que quelqu'un pourrait m'expliquer la marche à suivre ?

merci

Posté le : 30/11/2009 12:15
Partager Twitter Partagez cette article sur GG+
Re: Ajouter un champ au module News
Supporter Xoops
Inscrit: 09/01/2005 13:37
De Breizh
Messages: 16972
Bonjour,

Et qu'as-tu fais pour l'instant, cela nous serait plus pratique quelles lignes de code pour voir où tu aurais pu te tromper

@+

Posté le : 30/11/2009 12:20

La connaissance s'accroît quand on la partage ...
Partager Twitter Partagez cette article sur GG+
Re: Ajouter un champ au module News
Régulier
Inscrit: 22/03/2006 10:49
Messages: 197
Alors, pas mal de modifs.

Premièrement, j'ai cloné news 1.63 avec le fichier clone-news.php. J'ai appellé ce nouveau module "course"

Ensuite, j'ai appliqué le hack news-event pourque mon module soit un gestionnaire d'évènements. j'ai bien fait attention à renommer tout ce qui devait l'être

Jusque là tout fonctionne bien.

Je souhaite ajouter un champ "prix" pour chaque course de mon nouveau module.

J'ai donc d'abord ajouté un nouveau champ à la table stories qui s'appelle "prix" et qui est en fin de table.

Ensuite, Les fichiers modifiés sont :
- article.php
- submit.php
- class.coursestory.php (ancien class.newsstory.php)
- include/storyform.inc.php

chaque modif est encadrée par :
//ajout irishcofee
//fin ajout irishcofee


je les mets ici à suivre (ctrl+F "price" pour retrouver toutes les modifs)

Posté le : 30/11/2009 12:34
Partager Twitter Partagez cette article sur GG+
Re: Ajouter un champ au module News
Régulier
Inscrit: 22/03/2006 10:49
Messages: 197
ARTICLE.PHP
modif a la ligne 187

<?php
// $Id: article.php,v 1.15 2004/09/02 17:04:07 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 //
//  ------------------------------------------------------------------------ //
/**
 * Article's page
 *
 * This page is used to see an article (or story) and is mainly called from
 * the module's index page.
 *
 * If no story Id has been placed on the URL or if the story is not yet published
 * then the page will redirect user to the module's index.
 * If the user does not have the permissions to see the article, he is also redirected
 * to the module's index page but with a error message saying :
 *     "Sorry, you don't have the permission to access this area"
 *
 * Each time a page is seen, and only if we are on the first page, its counter of hits is
 * updated
 *
 * Each file(s) attached to the article is visible at the bottom of the article and can
 * be downloaded
 *
 * Notes :
 * - To create more than one page in your story, use the tag [pagebreak]
 * - If you are a module's admin, you have the possibility to see two links at the bottom
 *   of the article, "Edit & Delete"
 *
 * @package Course
 * @author Xoops Modules Dev Team
 * @copyright (c) The Xoops Project - www.xoops.org
 *
 * Parameters received by this page :
 * @param int storyid    Id of the story we want to see
 * @param int page        page's number (in the case where there are more than one page)
 *
 * @page_title            Article's title - Topic's title - Module's name
 *
 * @template_name        course_article.html wich will call course_item.html
 *
 * Template's variables :
 * @template_var    string    pagenav    some links to navigate thru pages
 * @template_var    array     story    Contains all the information about the story
 *                                    Structure :
 * @template_var                    int        id            Story's ID
 * @template_var                    string    posttime    Story's date of publication
 * @template_var                    string    title        A link to go and see all the articles in the same topic and the story's title
 * @template_var                    string    course_title    Just the course title
 * @template_var                    string    topic_title    Just the topic's title
 * @template_var                    string    text        Defined as "The scoop"
 * @template_var                    string    poster        A link to see the author's profil and his name or "Anonymous"
 * @template_var                    int        posterid    Author's uid (or 0 if it's an anonymous or a user wich does not exist any more)
 * @template_var                    string    morelink    Never used ???? May be it could be deleted
 * @template_var                    string    adminlink    A link to Edit or Delete the story or a blank string if you are not the module's admin
 * @template_var                    string    topicid        Course topic's Id
 * @template_var                    string    topic_color    Topic's color
 * @template_var                    string    imglink        A link to go and see the topic of the story with the topic's picture (if it exists)
 * @template_var                    string    align        Topic's image alignement
 * @template_var                    int        hits        Story's counter of visits
 * @template_var                    string    mail_link    A link (with a mailto) to email the story's URL to someone
 * @template_var    string    lang_printerpage    Used in the link and picture to have a "printable version" (fixed text)
 * @template_var    string     lang_on        Fixed text "On" ("published on")
 * @template_var    string    lang_postedby    Fixed text "Posted by"
 * @template_var    string    lang_reads    Fixed text "Reads"
 * @template_var    string    course_by_the_same_author_link    According the the module's option named "coursebythisauthor", it contains a link to see all the article's course_stories
 * @template_var    int        summary_count    Number of course_stories really visibles in the summary table
 * @template_var    boolean    showsummary    According to the module's option named "showsummarytable", this contains "True" of "False"
 * @template_var    array    summary    Contains the required information to create a summary table at the bottom of the article. Note, we use the module's option "storyhome" to determine the maximum number of course_stories visibles in this summary table
 *                                     Structure :
 * @template_var                    int        story_id        Story's ID
 * @template_var                    string    story_title        Story's title
 * @template_var                    int        story_hits        Counter of hits
 * @template_var                    string    story_published    Story's date of creation
 * @template_var    string    lang_attached_files    Fixed text "Attached Files:"
 * @template_var    int        attached_files_count    Number of files attached to the story
 * @template_var    array    attached_files    Contains the list of all the files attached to the story
 *                                    Structure :
 * @template_var                    int        file_id                File's ID
 * @template_var                    string    visitlink            Link to download the file
 * @template_var                    string    file_realname        Original filename (not the real one use to store the file but the one it have when it was on the user hard disk)
 * @template_var                    string    file_attacheddate    Date to wich the file was attached to the story (in general that's equal to the article's creation date)
 * @template_var                    string    file_mimetype        File's mime type
 * @template_var                    string    file_downloadname    Real name of the file on the webserver's disk (changed by the module)
 * @template_var    boolean    nav_links    According to the module's option named "showprevnextlink" it contains "True" or "False" to know if we have to show two links to go to the previous and next article
 * @template_var    int        previous_story_id    Id of the previous story (according to the published date and to the perms)
 * @template_var    int        next_story_id        Id of the next story (according to the published date and to the perms)
 * @template_var    string    previous_story_title    Title of the previous story
 * @template_var    string    next_story_title        Title of the next story
 * @template_var    string    lang_previous_story        Fixed text "Previous article"
 * @template_var    string    lang_next_story            Fixed text "Next article"
 * @template_var    string    lang_other_story        Fixed text "Other articles"
 * @template_var    boolean    rates    To know if rating is enable or not
 * @template_var    string    lang_ratingc    Fixed text "Rating: "
 * @template_var    string    lang_ratethiscourse    Fixed text "Rate this Course"
 * @template_var    float    rating    Article's rating
 * @template_var    string    votes    "1 vote" or "X votes"
 * @template_var    string    topic_path    A path from the root to the current topic (of the current course)
 */
include_once '../../mainfile.php';
include_once 
XOOPS_ROOT_PATH.'/modules/course/class/class.coursestory.php';
include_once 
XOOPS_ROOT_PATH.'/modules/course/class/class.sfiles.php';
include_once 
XOOPS_ROOT_PATH.'/class/xoopstree.php';
include_once 
XOOPS_ROOT_PATH.'/modules/course/include/functions.php';
include_once 
XOOPS_ROOT_PATH.'/modules/course/class/class.coursetopic.php';
include_once 
XOOPS_ROOT_PATH.'/modules/course/class/keyhighlighter.class.php';
include_once 
XOOPS_ROOT_PATH.'/modules/course/config.php';

$storyid = (isset($_GET['storyid'])) ? intval($_GET['storyid']) : 0;

if (empty(
$storyid)) {
    
redirect_header(XOOPS_URL.'/modules/course/index.php',2,_NW_NOSTORY);
    exit();
}

$myts =& MyTextSanitizer::getInstance();

// Not yet published
$article = new CourseStory($storyid);
if ( 
$article->published() == || $article->published() > time() ) {
    
redirect_header(XOOPS_URL.'/modules/course/index.php'2_NW_NOTYETSTORY);
    exit();
}
// Expired
if ( $article->expired() != && $article->expired() < time() ) {
    
redirect_header(XOOPS_URL.'/modules/course/index.php'2_NW_NOSTORY);
    exit();
}

$gperm_handler =& xoops_gethandler('groupperm');
if (
is_object($xoopsUser)) {
    
$groups $xoopsUser->getGroups();
} else {
    
$groups XOOPS_GROUP_ANONYMOUS;
}
if (!
$gperm_handler->checkRight('course_view'$article->topicid(), $groups$xoopsModule->getVar('mid'))) {
    
redirect_header(XOOPS_URL.'/modules/course/index.php'3_NOPERM);
    exit();
}

$storypage = isset($_GET['page']) ? intval($_GET['page']) : 0;
$dateformat course_coursegetmoduleoption('dateformat');
$hcontent='';

/**
 * update counter only when viewing top page and when you are not the author or an admin
 */
if (empty($_GET['com_id']) && $storypage == 0) {
    if(
is_object($xoopsUser)) {
        if( (
$xoopsUser->getVar('uid')==$article->uid()) || course_courseis_admin_group()) {
            
// nothing ! ;-)
        
} else {
            
$article->updateCounter();
        }
    } else {
        
$article->updateCounter();
    }
}
$xoopsOption['template_main'] = 'course_article.html';
include_once 
XOOPS_ROOT_PATH.'/header.php';

$story['id'] = $storyid;
$story['posttime'] = formatTimestamp($article->published(),$dateformat);
$story['booked'] = formatTimestamp($article->booked(),$dateformat);
$story['bookedend'] = formatTimestamp($article->booked(),$dateformat);
//ajout irishcofee
$story['price'] = $article->price();
//fin ajout irishcofee
$story['course_title'] = $article->title();
$story['title'] = $article->textlink().'&nbsp;:&nbsp;'.$article->title();
$story['topic_title'] = $article->textlink();


$story['text'] = $article->hometext();
$bodytext $article->bodytext();

if (
xoops_trim($bodytext) != '') {
    
$articletext = array();
    if(
course_coursegetmoduleoption('enhanced_pagenav')) {
        
$articletext preg_split('/([pagebreak:|[pagebreak)(.*)(])/iU'$bodytext);
        
$arr_titles = array();
        
$auto_summary $article->auto_summary($bodytext$arr_titles);
        
$bodytext str_replace('[summary]'$auto_summary$bodytext);
        
$articletext[$storypage] = str_replace('[summary]'$auto_summary$articletext[$storypage]);
        
$story['text'] = str_replace('[summary]'$auto_summary$story['text']);
    } else {
        
$articletext explode('[pagebreak]'$bodytext);
    }

    
$story_pages count($articletext);

    if (
$story_pages 1) {
        include_once 
XOOPS_ROOT_PATH.'/modules/course/include/pagenav.php';
        
$pagenav = new XoopsPageNav($story_pages1$storypage'page''storyid='.$storyid);
        if(
course_isbot()) {         // A bot is reading the articles, we are going to show him all the links to the pages
            
$xoopsTpl->assign('pagenav'$pagenav->renderNav($story_pages));
        } else {
            if(
course_coursegetmoduleoption('enhanced_pagenav')) {
                
$xoopsTpl->assign('pagenav'$pagenav->renderEnhancedSelect(true$arr_titles));
            } else {
                
$xoopsTpl->assign('pagenav'$pagenav->renderNav());
            }
        }

        if (
$storypage == 0) {
            
$story['text'] = $story['text'].'<br />'.course_coursegetmoduleoption('advertisement').'<br />'.$articletext[$storypage];
        } else {
            
$story['text'] = $articletext[$storypage];
        }
    } else {
        
$story['text'] = $story['text'].'<br />'.course_coursegetmoduleoption('advertisement').'<br />'.$bodytext;
    }
}
// Publicité
$xoopsTpl->assign('advertisement'course_coursegetmoduleoption('advertisement'));

// ****************************************************************************************************************
function my_highlighter ($matches) {
    
$color course_coursegetmoduleoption('highlightcolor');
    if(
substr($color,0,1)!='#') {
        
$color='#'.$color;
    }
    return 
'<span style="font-weight: bolder; background-color: '.$color.';">' $matches[0] . '</span>';
}

$highlight false;
$highlight course_coursegetmoduleoption('keywordshighlight');

if(
$highlight && isset($_GET['keywords']))
{
    
$keywords=$myts->htmlSpecialChars(trim(urldecode($_GET['keywords'])));
    
$h= new keyhighlighter ($keywordstrue 'my_highlighter');
    
$story['text'] = $h->highlight($story['text']);
}
// ****************************************************************************************************************

$story['poster'] = $article->uname();
if ( 
$story['poster'] ) {
    
$story['posterid'] = $article->uid();
    
$story['poster'] = '<a href="'.XOOPS_URL.'/userinfo.php?uid='.$story['posterid'].'">'.$story['poster'].'</a>';
    
$tmp_user = new XoopsUser($article->uid());
    
$story['poster_avatar'] = XOOPS_UPLOAD_URL.'/'.$tmp_user->getVar('user_avatar');
    
$story['poster_signature'] = $tmp_user->getVar('user_sig');
    
$story['poster_email'] = $tmp_user->getVar('email');
    
$story['poster_url'] = $tmp_user->getVar('url');
    
$story['poster_from'] = $tmp_user->getVar('user_from');
    unset(
$tmp_user);
} else {
    
$story['poster'] = '';
    
$story['posterid'] = 0;
    
$story['poster_avatar'] = '';
    
$story['poster_signature'] = '';
    
$story['poster_email'] = '';
    
$story['poster_url'] = '';
    
$story['poster_from'] = '';
    if(
course_coursegetmoduleoption('displayname')!=3) {
        
$story['poster'] = $xoopsConfig['anonymous'];
    }
}
$story['morelink'] = '';
$story['adminlink'] = '';
unset(
$isadmin);

if(
is_object($xoopsUser)) {
    if( 
$xoopsUser->isAdmin($xoopsModule->getVar('mid')) || (course_coursegetmoduleoption('authoredit') && $article->uid() == $xoopsUser->getVar('uid')) ) {
        
$isadmin true;
        
$story['adminlink'] = $article->adminlink();
    }
}
$story['topicid'] = $article->topicid();
$story['topic_color'] = '#'.$myts->displayTarea($article->topic_color);

$story['imglink'] = '';
$story['align'] = '';
if ( 
$article->topicdisplay() ) {
    
$story['imglink'] = $article->imglink();
    
$story['align'] = $article->topicalign();
}
$story['hits'] = $article->counter();
$story['mail_link'] = 'mailto:?subject='.sprintf(_NW_INTARTICLE,$xoopsConfig['sitename']).'&amp;body='.sprintf(_NW_INTARTFOUND$xoopsConfig['sitename']).':  '.XOOPS_URL.'/modules/course/article.php?storyid='.$article->storyid();
$xoopsTpl->assign('lang_printerpage'_NW_PRINTERFRIENDLY);
$xoopsTpl->assign('lang_sendstory'_NW_SENDSTORY);
$xoopsTpl->assign('lang_pdfstory'_NW_MAKEPDF);
$xoopsTpl->assign('lang_on'_ON);
$xoopsTpl->assign('lang_postedby'_POSTEDBY);
$xoopsTpl->assign('lang_reads'_READS);
$xoopsTpl->assign('mail_link''mailto:?subject='.sprintf(_NW_INTARTICLE,$xoopsConfig['sitename']).'&amp;body='.sprintf(_NW_INTARTFOUND$xoopsConfig['sitename']).':  '.XOOPS_URL.'/modules/course/article.php?storyid='.$article->storyid());

$xoopsTpl->assign('lang_attached_files',_NW_ATTACHEDFILES);
$sfiles = new sFiles();
$filesarr $coursefiles = array();
$filesarr=$sfiles->getAllbyStory($storyid);
$filescount=count($filesarr);
$xoopsTpl->assign('attached_files_count',$filescount);
if(
$filescount>0) {
    foreach (
$filesarr as $onefile)    {
        
$coursefiles[]=Array('file_id'=>$onefile->getFileid(), 'visitlink' => XOOPS_URL.'/modules/course/visit.php?fileid='.$onefile->getFileid(),'file_realname'=>$onefile->getFileRealName(), 'file_attacheddate'=>formatTimestamp($onefile->getDate(),$dateformat), 'file_mimetype'=>$onefile->getMimetype(), 'file_downloadname'=>XOOPS_UPLOAD_URL.'/'.$onefile->getDownloadname());
    }
    
$xoopsTpl->assign('attached_files',$coursefiles);
}

/**
 * Create page's title
*/
$complement '';
if(
course_coursegetmoduleoption('enhanced_pagenav') && (is_array($arr_titles) && isset($arr_titles,$storypage) && $storypage>0)) {
    
$complement ' - '.$arr_titles[$storypage];
}
$xoopsTpl->assign('xoops_pagetitle'$article->title() . $complement' - ' $article->topic_title() . ' - ' $myts->htmlSpecialChars($xoopsModule->name()));

if(
course_coursegetmoduleoption('coursebythisauthor')) {
    
$xoopsTpl->assign('course_by_the_same_author_link',sprintf("<a href='%s?uid=%d'>%s</a>",XOOPS_URL.'/modules/course/coursebythisauthor.php',$article->uid(),_NW_courseSAMEAUTHORLINK));
}

/**
 * Create a clickable path from the root to the current topic (if we are viewing a topic)
 * Actually this is not used in the default's templates but you can use it as you want
 * Uncomment the code to be able to use it
 */
if($cfg['create_clickable_path']) {
    
$mytree = new XoopsTree($xoopsDB->prefix('course_topics'),'topic_id','topic_pid');
    
$topicpath $mytree->getNicePathFromId($article->topicid(), 'topic_title''index.php?op=1');
    
$xoopsTpl->assign('topic_path'$topicpath);
    unset(
$mytree);
}


/**
 * Summary table
 *
 * When you are viewing an article, you can see a summary table containing
 * the first n links to the last published course.
 * This summary table is visible according to a module's option (showsummarytable)
 * The number of items is equal to the module's option "storyhome" ("Select the number
 * of course items to display on top page")
 * We also use the module's option "restrictindex" ("Restrict Topics on Index Page"), like
 * this you (the webmaster) select if users can see restricted course_stories or not.
 */
if (course_coursegetmoduleoption('showsummarytable')) {
    
$xoopsTpl->assign('showsummary'true);
    
$xoopsTpl->assign('lang_other_story',_NW_OTHER_ARTICLES);
    
$count=0;
    
$tmparticle = new CourseStory();
    
$infotips=course_coursegetmoduleoption('infotips');
    
$sarray $tmparticle->getAllPublished($cfg['article_summary_items_count'], 0$xoopsModuleConfig['restrictindex']);
    if(
count($sarray)>0) {
        foreach (
$sarray as $onearticle) {
            
$count++;
            
$htmltitle='';
            
$tooltips='';
            
$htmltitle='';
            if(
$infotips>0) {
                
$tooltips course_coursemake_infotips($onearticle->hometext());
                
$htmltitle=' title="'.$tooltips.'"';
            }
             
$xoopsTpl->append('summary', array('story_id'=>$onearticle->storyid(), 'htmltitle'=>$htmltitle'infotips'=>$tooltips'story_title'=>$onearticle->title(), 'story_hits'=>$onearticle->counter(), 'story_published'=>formatTimestamp($onearticle->published,$dateformat)));
           }
       }
       
$xoopsTpl->assign('summary_count',$count);
    unset(
$tmparticle);
} else {
    
$xoopsTpl->assign('showsummary'false);
}


/**
 * Show a link to go to the previous article and to the next article
 *
 * According to a module's option "showprevnextlink" ("Show Previous and Next link ?")
 * you can display, at the bottom of each article, two links used to navigate thru course_stories.
 * This feature uses the module's option "restrictindex" so that we can, or can't see
 * restricted course_stories
 */
if (course_coursegetmoduleoption('showprevnextlink')) {
    
$xoopsTpl->assign('nav_links'true);
    
$tmparticle = new CourseStory();
    
$nextId $previousId = -1;
    
$next $previous = array();
    
$previousTitle $nextTitle '';
    
    
$next $tmparticle->getNextArticle($storyid$xoopsModuleConfig['restrictindex']);
    if(
count($next) > 0) {
        
$nextId $next['storyid'];
        
$nextTitle $next['title'];
    }
    
    
$previous $tmparticle->getPreviousArticle($storyid$xoopsModuleConfig['restrictindex']);
    if(
count($previous) > 0) {
        
$previousId $previous['storyid'];
        
$previousTitle $previous['title'];
    }    
    
       
$xoopsTpl->assign('previous_story_id',$previousId);
       
$xoopsTpl->assign('next_story_id',$nextId);
       if(
$previousId 0) {
           
$xoopsTpl->assign('previous_story_title',$previousTitle);
           
$hcontent.=sprintf("<link rel="Prev" title="%s" href="%s/" />n"$previousTitle,XOOPS_URL.'/modules/course/article.php?storyid='.$previousId);
       }

       if(
$nextId 0) {
           
$xoopsTpl->assign('next_story_title',$nextTitle);
           
$hcontent.=sprintf("<link rel="Next" title="%s" href="%s/" />n"$nextTitle,XOOPS_URL.'/modules/course/article.php?storyid='.$nextId);
       }
       
$xoopsTpl->assign('lang_previous_story',_NW_PREVIOUS_ARTICLE);
       
$xoopsTpl->assign('lang_next_story',_NW_NEXT_ARTICLE);
       unset(
$tmparticle);
} else {
    
$xoopsTpl->assign('nav_links'false);
}

/**
 * Manage all the meta datas
 */
course_CreateMetaDatas($article);



/**
 * Show a "Bookmark this article at these sites" block ?
 */
if(course_coursegetmoduleoption('bookmarkme')) {
    
$xoopsTpl->assign('bookmarkme'true);
    
$xoopsTpl->assign('encoded_title'rawurlencode($article->title()));
} else {
    
$xoopsTpl->assign('bookmarkme'false);
}


/**
 * Enable users to vote
 *
 * According to a module's option, "ratecourse", you can display a link to rate the current course
 * The actual rate in showed (and the number of votes)
 * Possible modification, restrict votes to registred users
 */
$other_test true;
if(
$cfg['config_rating_registred_only']) {
    if(isset(
$xoopsUser) && is_object($xoopsUser)) {
        
$other_test true;
    } else {
        
$other_test false;
    }
}

if (
course_coursegetmoduleoption('ratecourse') && $other_test) {
    
$xoopsTpl->assign('rates'true);
    
$xoopsTpl->assign('lang_ratingc'_NW_RATINGC);
    
$xoopsTpl->assign('lang_ratethiscourse'_NW_RATETHIScourse);
    
$story['rating'] = number_format($article->rating(), 2);
    if (
$article->votes == 1) {
        
$story['votes'] = _NW_ONEVOTE;
    } else {
        
$story['votes'] = sprintf(_NW_NUMVOTES,$article->votes);
    }
} else {
    
$xoopsTpl->assign('rates'false);
}

$xoopsTpl->assign('story'$story);

include_once 
XOOPS_ROOT_PATH.'/include/comment_view.php';
include_once 
XOOPS_ROOT_PATH.'/footer.php';
?>

Posté le : 30/11/2009 12:44
Partager Twitter Partagez cette article sur GG+
Re: Ajouter un champ au module News
Régulier
Inscrit: 22/03/2006 10:49
Messages: 197
SUBMIT.PHP
plusieurs ajouts repérables par "ajout irishcofee"

<?php
// $Id: submit.php,v 1.23 2004/09/01 17:48:07 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')) {
    include_once 
'../../mainfile.php';
}
include_once 
XOOPS_ROOT_PATH.'/modules/course/class/class.coursestory.php';
include_once 
XOOPS_ROOT_PATH.'/modules/course/class/class.sfiles.php';
include_once 
XOOPS_ROOT_PATH.'/modules/course/class/class.coursetopic.php';
include_once 
XOOPS_ROOT_PATH.'/class/uploader.php';
include_once 
XOOPS_ROOT_PATH.'/header.php';
include_once 
XOOPS_ROOT_PATH.'/modules/course/include/functions.php';
if (
file_exists(XOOPS_ROOT_PATH.'/modules/course/language/'.$xoopsConfig['language'].'/admin.php')) {
    include_once 
XOOPS_ROOT_PATH.'/modules/course/language/'.$xoopsConfig['language'].'/admin.php';
} else {
    include_once 
XOOPS_ROOT_PATH.'/modules/course/language/english/admin.php';
}
$myts =& MyTextSanitizer::getInstance();
$module_id $xoopsModule->getVar('mid');
$storyid=0;

if (
is_object($xoopsUser)) {
    
$groups $xoopsUser->getGroups();
} else {
    
$groups XOOPS_GROUP_ANONYMOUS;
}

$gperm_handler =& xoops_gethandler('groupperm');

if (isset(
$_POST['topic_id'])) {
    
$perm_itemid intval($_POST['topic_id']);
} else {
    
$perm_itemid 0;
}
//If no access
if (!$gperm_handler->checkRight('course_submit'$perm_itemid$groups$module_id)) {
    
redirect_header(XOOPS_URL.'/modules/course/index.php'3_NOPERM);
    exit();
}
$op 'form';

//If approve privileges
$approveprivilege 0;
if (
is_object($xoopsUser) && $gperm_handler->checkRight('course_approve'$perm_itemid$groups$module_id)) {
    
$approveprivilege 1;
}

if (isset(
$_POST['preview'])) {
    
$op 'preview';
} elseif (isset(
$_POST['post'])) {
    
$op 'post';
}
elseif ( isset(
$_GET['op']) && isset($_GET['storyid'])) {
    
// Verify that the user can edit or delete an article
    
if( $_GET['op'] == 'edit' || $_GET['op'] == 'delete' ) {
        if(
$xoopsModuleConfig['authoredit']==1) {
            
$tmpstory = new CourseStory(intval($_GET['storyid']));
            if(
is_object($xoopsUser) && $xoopsUser->getVar('uid')!=$tmpstory->uid() && !course_courseis_admin_group()) {
                
redirect_header(XOOPS_URL.'/modules/course/index.php'3_NOPERM);
                exit();
            }
        } else {    
// Users can't edit their articles
            
if(!course_courseis_admin_group()) {
                
redirect_header(XOOPS_URL.'/modules/course/index.php'3_NOPERM);
                exit();
            }
        }
    }

    if (
$approveprivilege && $_GET['op'] == 'edit') {
        
$op 'edit';
        
$storyid intval($_GET['storyid']);
    }
    elseif (
$approveprivilege && $_GET['op'] == 'delete') {
        
$op 'delete';
        
$storyid intval($_GET['storyid']);
    }
    else {
        if(
course_coursegetmoduleoption('authoredit') && is_object($xoopsUser) && isset($_GET['storyid']) && ($_GET['op']=='edit' || $_POST['op']=='preview' || $_POST['op']=='post')) {
            
$storyid=0;
            
$storyid = isset($_GET['storyid']) ? intval($_GET['storyid']) : intval($_POST['storyid']);
            if(!empty(
$storyid)) {
                
$tmpstory = new CourseStory($storyid);
                if(
$tmpstory->uid()==$xoopsUser->getVar('uid')) {
                    
$op= isset($_GET['op']) ? $_GET['op'] : $_POST['post'];
                    unset(
$tmpstory);
                    
$approveprivilege=1;
                } else {
                    unset(
$tmpstory);
                    if(!
course_courseis_admin_group()) {
                        
redirect_header(XOOPS_URL.'/modules/course/index.php'3_NOPERM);
                        exit();
                    } else {
                        
$approveprivilege=1;
                    }
                }
            }
        } else {
            if(!
course_courseis_admin_group()) {
                unset(
$tmpstory);
                
redirect_header(XOOPS_URL.'/modules/course/index.php'3_NOPERM);
                exit();
            } else {
                
$approveprivilege=1;
            }
        }
    }
}

switch (
$op) {
    case 
'edit':
        if (!
$approveprivilege) {
            
redirect_header(XOOPS_URL.'/modules/course/index.php'0_NOPERM);
            exit();
            break;
        }
        
//if($storyid==0 && isset($_POST['storyid'])) {
         //    $storyid=intval($_POST['storyid']);
           //}
        
$story = new CourseStory($storyid);
        if (!
$gperm_handler->checkRight('course_view'$story->topicid(), $groups$module_id)) {
            
redirect_header(XOOPS_URL.'/modules/course/index.php'0_NOPERM);
            exit();
        }
        echo
"<table width='100%' border='0' cellspacing='1' class='outer'><tr><td class="odd">";
        echo 
'<h4>' _AM_EDITARTICLE '</h4>';
        
$title $story->title('Edit');
        
$hometext $story->hometext('Edit');
        
$bodytext $story->bodytext('Edit');
        
$nohtml $story->nohtml();
        
$nosmiley $story->nosmiley();
        
$description $story->description();
        
$keywords $story->keywords();
        
$ihome $story->ihome();
        
$courseauthor=$story->uid();
        
$topicid $story->topicid();
        
$notifypub=$story->notifypub();
        
$approve 0;
        
$published $story->published();
        if (isset(
$published) && $published 0) {
            
$approve 1;
        }
        if ( 
$story -> published() != 0) {
            
$published $story->published();
        }
        if ( 
$story -> expired() != 0) {
            
$expired $story->expired();
        } else {
            
$expired 0;
        }
        
//blueteen - events - begin
        
if ( $story -> booked() != 0) {
            
$booked $story->booked();
        } else {
            
$booked 0;
        }
        if ( 
$story -> bookedend() != 0) {
            
$bookedend $story->bookedend();
        } else {
            
$bookedend 0;
        }
        
//blueteen - events - end
        //ajout irishcofee
        
if ( $story -> price() != 0) {
            
$price $story->price();
        } else {
            
$price 0;}
            
//fin ajout irishcofee
        
$type $story -> type();
        
$topicdisplay $story -> topicdisplay();
        
$topicalign $story -> topicalignfalse );
        include_once 
XOOPS_ROOT_PATH.'/modules/course/include/storyform.inc.php';
        echo
'</td></tr></table>';
        break;

    case 
'preview':
        
$topic_id intval($_POST['topic_id']);
        
$xt = new CourseTopic($topic_id);
        if(isset(
$_GET['storyid'])) {
            
$storyid=intval($_GET['storyid']);
        } else {
            if(isset(
$_POST['storyid'])) {
                
$storyid=intval($_POST['storyid']);
            } else {
                
$storyid=0;
            }
        }

        if (!empty(
$storyid)) {
            
$story = new CourseStory($storyid);
            
$published $story -> published();
            
$expired $story -> expired();
            
//ajout irishcofee
            
$price $story -> price();
            
//fin ajout irishcofee
            
$booked $story -> booked();//blueteen - events
            
$bookedend $story -> bookedend();//blueteen - events
        
} else {
            
$story = new CourseStory();
            
$published = isset($_POST['publish_date']) ? $_POST['publish_date'] : 0;
            if(!empty(
$published) && isset($_POST['autodate']) && intval($_POST['autodate']==1)) {
                
$published=strtotime($published['date']) + $published['time'];
            } else {
                
$published=0;
            }
            
$expired= isset($_POST['expiry_date']) ? $_POST['expiry_date'] : 0;
            if(!empty(
$expired) && isset($_POST['autoexpdate']) && intval($_POST['autoexpdate']==1)) {
                
$expired=strtotime($expired['date']) + $expired['time'];
            } else {
                
$expired=0;
            }
            
            
//ajout ajout irishcofee
            
$price = isset($_POST['price']) ? $_POST['price'] : 0;
            
//fin ajout irishcofee
            //blueteen - events - begin
            
$booked = isset($_POST['booked_date']) ? $_POST['booked_date'] : 0;
            
$bookedend = isset($_POST['bookedend_date']) ? $_POST['bookedend_date'] : 0;
            if(!empty(
$booked) && !empty($bookedend) && isset($_POST['autobookdate']) && intval($_POST['autobookdate']==1)) {
                
$booked strtotime($booked['date']) + $booked['time'];
                
$bookedend strtotime($bookedend['date']) + $bookedend['time'];
            } else {
                
$booked 0;
            }
            
//blueteen - events - end
        
}
        
$topicid $topic_id;
        if(isset(
$_POST['topicdisplay'])) {
            
$topicdisplay=intval($_POST['topicdisplay']);
        } else {
            
$topicdisplay=1;
        }

        
$approve = isset($_POST['approve']) ? intval($_POST['approve']) : 0;
        
$topicalign 'R';
        if(isset(
$_POST['topicalign'])) {
            
$topicalign=$_POST['topicalign'];
        }
        
$story->setTitle($_POST['title']);
        
$story->setHometext($_POST['hometext']);
        if (
$approveprivilege) {
            
$story->setTopicdisplay($topicdisplay);
            
$story->setTopicalign($topicalign);
            
$story->setBodytext($_POST['bodytext']);
            if(
course_coursegetmoduleoption('metadata')) {
                
$story->Setkeywords($_POST['keywords']);
                
$story->Setdescription($_POST['description']);
                
$story->setIhome(intval($_POST['ihome']));
            }
        } else {
            
$noname = isset($_POST['noname']) ? intval($_POST['noname']) : 0;
        }

        if (
$approveprivilege || (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid()))) {
            if(isset(
$_POST['author'])) {
                
$story->setUid(intval($_POST['author']));
            }
        }

        
$notifypub = isset($_POST['notifypub']) ? intval($_POST['notifypub']) : 0;

        
$nosmiley=isset($_POST['nosmiley']) ? intval($_POST['nosmiley']) : 0;
        if (isset(
$nosmiley) && ($nosmiley == || $nosmiley == 1)) {
            
$story -> setNosmiley($nosmiley);
        } else {
            
$nosmiley 0;
        }
        if (
$approveprivilege) {
            
$nohtml = isset($_POST['nohtml']) ? intval($_POST['nohtml']) : 0;
            
$story->setNohtml($nohtml);
            if (!isset(
$_POST['approve'])) {
                
$approve 0;
            }
        } else {
            
$story->setNohtml 1;
        }

        
$title $story->title('InForm');
        
$hometext $story->hometext('InForm');
          if (
$approveprivilege) {
              
$bodytext $story->bodytext('InForm');
              
$ihome $story -> ihome();
              
$description $story->description('E');
              
$keywords $story->keywords('E');
          }

        
//Display post preview
        
$courseauthor=$story->uid();
        
$p_title $story->title('Preview');
        
$p_hometext $story->hometext('Preview');
        if (
$approveprivilege) {
            
$p_bodytext $story->bodytext('Preview');
            
$p_hometext .= '<br /><br />'.$p_bodytext;
        }
        
$topicalign2 = isset($story->topicalign) ? 'align="'.$story->topicalign().'"' '';
        
$p_hometext = (($xt->topic_imgurl() != '') && $topicdisplay) ? '<img src="images/course_topics/'.$xt->topic_imgurl().'" '.$topicalign2.' alt="" />'.$p_hometext $p_hometext;
        
themecenterposts($p_title$p_hometext);

        
//Display post edit form
        
$returnside=intval($_POST['returnside']);
        include_once 
XOOPS_ROOT_PATH.'/modules/course/include/storyform.inc.php';
        break;

    case 
'post':
        
$nohtml_db = isset($_POST['nohtml']) ? $_POST['nohtml'] : 1;
        if (
is_object($xoopsUser) ) {
            
$uid $xoopsUser->getVar('uid');
            if (
$approveprivilege) {
                
$nohtml_db = empty($_POST['nohtml']) ? 1;
            }
            if (isset(
$_POST['author']) && ($approveprivilege || $xoopsUser->isAdmin($xoopsModule->mid())) ) {
                
$uid=intval($_POST['author']);
            }
        } else {
            
$uid 0;
        }

        if(isset(
$_GET['storyid'])) {
            
$storyid=intval($_GET['storyid']);
        } else {
            if(isset(
$_POST['storyid'])) {
                
$storyid=intval($_POST['storyid']);
            } else {
                
$storyid=0;
            }
        }

        if (empty(
$storyid)) {
            
$story = new CourseStory();
            
$editmode false;
        } else {
            
$story = new CourseStory($storyid);
            
$editmode true;
        }
        
$story->setUid($uid);
        
$story->setTitle($_POST['title']);
        
$story->setHometext($_POST['hometext']);
        
$story->setTopicId(intval($_POST['topic_id']));
        
$story->setHostname(xoops_getenv('REMOTE_ADDR'));
        
$story->setNohtml($nohtml_db);
        
$nosmiley = isset($_POST['nosmiley']) ? intval($_POST['nosmiley']) : 0;
        
$story->setNosmiley($nosmiley);
        
$notifypub = isset($_POST['notifypub']) ? intval($_POST['notifypub']) : 0;
        
$story->setNotifyPub($notifypub);
        
$story->setType($_POST['type']);

        if (!empty( 
$_POST['autodate'] ) && $approveprivilege) {
            
$publish_date=$_POST['publish_date'];
            
$pubdate strtotime($publish_date['date']) + $publish_date['time'];
            
//$offset = $xoopsUser -> timezone() - $xoopsConfig['server_TZ'];
            //$pubdate = $pubdate - ( $offset * 3600 );
            
$story -> setPublished$pubdate );
        }
        if (!empty( 
$_POST['autoexpdate'] ) && $approveprivilege) {
            
$expiry_date=$_POST['expiry_date'];
            
$expiry_date strtotime($expiry_date['date']) + $expiry_date['time'];
            
$offset $xoopsUser -> timezone() - $xoopsConfig['server_TZ'];
            
$expiry_date $expiry_date - ( $offset 3600 );
            
$story -> setExpired$expiry_date );
        } else {
            
$story -> setExpired);
        }
        
//ajout irishcofee
        
$price=$_POST['price'];
        
//fin ajout irishcofee
        //blueteen - events - begin
        
if (!empty( $_POST['autobookdate'] ) && $approveprivilege) {
            
$booked_date=$_POST['booked_date'];
            
$booked_date strtotime($booked_date['date']) + $booked_date['time'];
            
$bookedend_date=$_POST['bookedend_date'];
            
$bookedend_date strtotime($bookedend_date['date']) + $bookedend_date['time'];
            
$offset $xoopsUser -> timezone() - $xoopsConfig['server_TZ'];
            
$booked_date $booked_date - ( $offset 3600 );
            
$bookedend_date $bookedend_date - ( $offset 3600 );

            
$story -> setBooked$booked_date );
            
$story -> setBookedend$bookedend_date );
        } else {
            
$story -> setBooked);
            
$story -> setBookedend);
        }
        
//blueteen - events - end
        
if ($approveprivilege) {
            if(
course_coursegetmoduleoption('metadata')) {
                
$story->Setdescription($_POST['description']);
                
$story->Setkeywords($_POST['keywords']);
            }
            
$story->setTopicdisplay($_POST['topicdisplay']);    // Display Topic Image ? (Yes or No)
            
$story->setTopicalign($_POST['topicalign']);        // Topic Align, 'Right' or 'Left'
               
$story->setIhome($_POST['ihome']);                // Publish in home ? (Yes or No)
            
if (isset($_POST['bodytext'])) {
                
$story->setBodytext($_POST['bodytext']);
            } else {
                
$story->setBodytext(' ');
            }

            
$approve = isset($_POST['approve']) ? intval($_POST['approve']) : 0;

            if (!
$story->published() && $approve) {
                
$story->setPublished(time());
            }
            if (!
$story->expired()) {
                
$story->setExpired(0);
            }
           

           
//blueteen - events - begin
            
if (!$story->booked()) {
                
$story->setBooked(0);
            }
            if (!
$story->bookedend()) {
                
$story->setBookedend(0);
            }
            
//blueteen - events - end
            
if(!$approve) {
                
$story->setPublished(0);
            }
        } elseif ( 
$xoopsModuleConfig['autoapprove'] == && !$approveprivilege) {
            if (empty(
$storyid)) {
                
$approve 1;
            } else {
                
$approve = isset($_POST['approve']) ? intval($_POST['approve']) : 0;
            }
            if(
$approve) {
                
$story->setPublished(time());
            } else {
                
$story->setPublished(0);
            }
            
$story->setExpired(0);
            
$story->setBooked(0);//blueteen - events
            
$story->setBookedend(0);//blueteen - events
            //ajout irishcofee
            
$story->setPrice$price );
            
//fin ajout irishcofee
            
$story->setTopicalign('R');
        } else {
            
$approve 0;
        }
        
$story->setApproved($approve);

        if(
$approve) {
            
course_courseupdateCache();
        }

        
// Increment author's posts count (only if it's a new article)
        // First case, it's not an anonyous, the story is approved and it's a new story
        
if($uid && $approve && empty($storyid)) {
            
$tmpuser=new xoopsUser($uid);
            
$member_handler =& xoops_gethandler('member');
            
$member_handler->updateUserByField($tmpuser'posts'$tmpuser->getVar('posts') + 1);
        }

        
// Second case, it's not an anonymous, the story is NOT approved and it's NOT a new story (typical when someone is approving a submited story)
        
if(is_object($xoopsUser) && $approve && !empty($storyid)) {
            
$storytemp = new CourseStory$storyid );
            if(!
$storytemp->published() && $storytemp->uid()>0) {    // the article has been submited but not approved
                
$tmpuser=new xoopsUser($storytemp->uid());
                
$member_handler =& xoops_gethandler('member');
                
$member_handler->updateUserByField($tmpuser'posts'$tmpuser->getVar('posts') + 1);
            }
            unset(
$storytemp);
        }

        
$result $story->store();
        if (
$result) {
            if (
$approveprivilege && course_coursegetmoduleoption('tags')) {
                
$tag_handler xoops_getmodulehandler('tag''tag');
                
$tag_handler->updateByItem($_POST['item_tag'], $story->storyid(), $xoopsModule->getVar('dirname'), 0);
            }

            if(!
$editmode) {
                
//     Notification
                // TODO: modifier afin qu'en cas de prépublication, la notification ne se fasse pas
                
$notification_handler =& xoops_gethandler('notification');
                
$tags = array();
                
$tags['STORY_NAME'] = $story->title();
                
$tags['STORY_URL'] = XOOPS_URL '/modules/' $xoopsModule->getVar('dirname') . '/article.php?storyid=' $story->storyid();
                
// If notify checkbox is set, add subscription for approve
                
if ($notifypub && $approve) {
                    include_once 
XOOPS_ROOT_PATH '/include/notification_constants.php';
                    
$notification_handler->subscribe('story'$story->storyid(), 'approve'XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE,$xoopsModule->getVar('mid'),$story->uid());
                }

                if (
$approve == 1) {
                    
$notification_handler->triggerEvent('global'0'new_story'$tags);
                    
$notification_handler->triggerEvent('story'$story->storyid(), 'approve'$tags);
                    
// Added by Lankford on 2007/3/23
                    
$notification_handler->triggerEvent('category'$story->topicid(), 'new_story'$tags);
                } else {
                    
$tags['WAITINGSTORIES_URL'] = XOOPS_URL '/modules/' $xoopsModule->getVar('dirname') . '/admin/index.php?op=newarticle';
                    
$notification_handler->triggerEvent('global'0'story_submit'$tags);
                }
            }

            
$allowupload false;
            switch (
$xoopsModuleConfig['uploadgroups']) {
                case 
1//Submitters and Approvers
                    
$allowupload true;
                    break;
                case 
2//Approvers only
                    
$allowupload $approveprivilege true false;
                    break;
                case 
3//Upload Disabled
                    
$allowupload false;
                    break;
            }

            if(
$allowupload) {
                
// Manage upload(s)
                
if(isset($_POST['delupload']) && count($_POST['delupload'])>0) {
                    foreach (
$_POST['delupload'] as $onefile) {
                        
$sfiles = new sFiles($onefile);
                        
$sfiles->delete();
                    }
                }

                if(isset(
$_POST['xoops_upload_file'])) {
                    
$fldname $_FILES[$_POST['xoops_upload_file'][0]];
                    
$fldname = (get_magic_quotes_gpc()) ? stripslashes($fldname['name']) : $fldname['name'];
                    if(
xoops_trim($fldname!='')) {
                        
$sfiles = new sFiles();
                        
$destname=$sfiles->createUploadName(XOOPS_UPLOAD_PATH,$fldname);
                        
/**
                         * You can attach files to your course
                         */
                        
$permittedtypes explode("n",str_replace("r",'',course_coursegetmoduleoption('mimetypes')));
                        
array_walk($permittedtypes'trim');
                        
$uploader = new XoopsMediaUploaderXOOPS_UPLOAD_PATH$permittedtypes$xoopsModuleConfig['maxuploadsize']);
                        
$uploader->setTargetFileName($destname);
                        if (
$uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
                            if (
$uploader->upload()) {
                                
$sfiles->setFileRealName($uploader->getMediaName());
                                
$sfiles->setStoryid($story->storyid());
                                
$sfiles->setMimetype($sfiles->giveMimetype(XOOPS_UPLOAD_PATH.'/'.$uploader->getMediaName()));
                                
$sfiles->setDownloadname($destname);
                                if(!
$sfiles->store()) {
                                    echo 
_AM_UPLOAD_DBERROR_SAVE;
                                }
                            } else {
                                echo 
_AM_UPLOAD_ERROR' ' $uploader->getErrors();
                            }
                        } else {
                            echo 
$uploader->getErrors();
                        }
                    }
                }
            }
        } else {
            echo 
_ERRORS;
        }
        
$returnside = isset($_POST['returnside']) ? intval($_POST['returnside']) : 0;
        if(!
$returnside) {
            
redirect_header(XOOPS_URL.'/modules/course/index.php',2,_NW_THANKS);
            exit();
        } else {
            
redirect_header(XOOPS_URL.'/modules/course/admin/index.php?op=newarticle',2,_NW_THANKS);
            exit();
        }
        break;

    case 
'form':
        
$xt = new CourseTopic();
        
$title '';
        
$hometext '';
        
$noname 0;
        
$nohtml 0;
        
$nosmiley 0;
        
$notifypub 1;
        
$topicid 0;
        if (
$approveprivilege) {
            
$description='';
            
$keywords='';
            
$topicdisplay 0;
            
$topicalign 'R';
            
$ihome 0;
            
$bodytext '';
            
$approve 0;
            
$autodate '';
            
$expired 0;
            
$published 0;
            
$booked 0;//blueteen - events
            
$bookedend 0;//blueteen - events
            
$price='';//ajout irishcofee
                            
}
        if(
$xoopsModuleConfig['autoapprove'] == 1) {
            
$approve=1;
        }
        include_once 
XOOPS_ROOT_PATH.'/modules/course/include/storyform.inc.php';
        break;
}
include_once 
XOOPS_ROOT_PATH.'/footer.php';
?>

Posté le : 30/11/2009 12:46
Partager Twitter Partagez cette article sur GG+
Re: Ajouter un champ au module News
Régulier
Inscrit: 22/03/2006 10:49
Messages: 197
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;
    }

}
?>

Posté le : 30/11/2009 12:46
Partager Twitter Partagez cette article sur GG+
Re: Ajouter un champ au module News
Régulier
Inscrit: 22/03/2006 10:49
Messages: 197
STORYFORM.INC.PHP

<?php
// $Id: storyform.inc.php,v 1.14 2004/09/03 17:30:43 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");
}

if (
file_exists(XOOPS_ROOT_PATH.'/language/'.$xoopsConfig['language'].'/calendar.php')) {
    include_once 
XOOPS_ROOT_PATH.'/language/'.$xoopsConfig['language'].'/calendar.php';
} else {
    include_once 
XOOPS_ROOT_PATH.'/language/english/calendar.php';
}
include_once 
XOOPS_ROOT_PATH.'/class/xoopsformloader.php';
include_once 
XOOPS_ROOT_PATH.'/modules/course/include/functions.php';
include_once 
XOOPS_ROOT_PATH.'/modules/course/config.php';

$sform = new XoopsThemeForm(_NW_SUBMITcourse"storyform"XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname').'/submit.php');
$sform->setExtra('enctype="multipart/form-data"');
$sform->addElement(new XoopsFormText(_NW_TITLE'title'50255$title), true);

// Topic's selection box
if (!isset($xt)) {
    
$xt = new CourseTopic();
}
if(
$xt->getAllTopicsCount()==0) {
       
redirect_header("index.php",4,_NW_POST_SORRY);
       exit();
}

include_once 
XOOPS_ROOT_PATH."/class/tree.php";
$allTopics $xt->getAllTopics($xoopsModuleConfig['restrictindex'],'course_submit');
$topic_tree = new XoopsObjectTree($allTopics'topic_id''topic_pid');
$topic_select $topic_tree->makeSelBox('topic_id''topic_title''-- '$topicidfalse);
$sform->addElement(new XoopsFormLabel(_NW_TOPIC$topic_select));

//If admin - show admin form
//TODO: Change to "If submit privilege"
if ($approveprivilege) {
    
//Show topic image?
    
$sform->addElement(new XoopsFormRadioYN(_AM_TOPICDISPLAY'topicdisplay'$topicdisplay));
    
//Select image position
    
$posselect = new XoopsFormSelect(_AM_TOPICALIGN'topicalign'$topicalign);
    
$posselect->addOption('R'_AM_RIGHT);
    
$posselect->addOption('L'_AM_LEFT);
    
$sform->addElement($posselect);
    
//Publish in home?
    //TODO: Check that pubinhome is 0 = no and 1 = yes (currently vice versa)
    
$sform->addElement(new XoopsFormRadioYN(_AM_PUBINHOME'ihome'$ihome_NO_YES));
}

// Course author
if ($approveprivilege && is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid())) {
    if(!isset(
$courseauthor)) {
        
$courseauthor=$xoopsUser->getVar('uid');
    }
    
$member_handler = &xoops_gethandler'member' );
    
$usercount $member_handler->getUserCount();
    if ( 
$usercount $cfg['config_max_users_list']) {
        
$sform->addElement(new XoopsFormSelectUser(_NW_AUTHOR,'author',true$courseauthor),false);
    } else {
        
$sform->addElement(new XoopsFormText(_NW_AUTHOR_ID'author'1010$courseauthor), false);
    }
}

$editor=course_getWysiwygForm(_NW_THESCOOP'hometext'$hometext1560'hometext_hidden');
$sform->addElement($editor,true);

//Extra info
//If admin -> if submit privilege
if ($approveprivilege) {
    
$editor2=course_getWysiwygForm(_AM_EXTEXT'bodytext'$bodytext1560'bodytext_hidden');
    
$sform->addElement($editor2,false);

    if(
course_coursegetmoduleoption('tags')) {
        
$itemIdForTag = isset($storyid) ? $storyid 0;
        require_once 
XOOPS_ROOT_PATH.'/modules/tag/include/formtag.php';
        
$sform->addElement(new XoopsFormTag('item_tag'60255$itemIdForTag0));
    }

    if(
course_coursegetmoduleoption('metadata')) {
        
$sform->addElement(new xoopsFormText(_NW_META_DESCRIPTION'description'50255$description), false);
        
$sform->addElement(new xoopsFormText(_NW_META_KEYWORDS'keywords'50255$keywords), false);
    }
}

// Manage upload(s)
$allowupload false;
switch (
$xoopsModuleConfig['uploadgroups'])
{
    case 
1//Submitters and Approvers
        
$allowupload true;
        break;
    case 
2//Approvers only
        
$allowupload $approveprivilege true false;
        break;
    case 
3//Upload Disabled
        
$allowupload false;
        break;
}

if(
$allowupload)
{
    if(
$op=='edit') {
        
$sfiles = new sFiles();
        
$filesarr=Array();
        
$filesarr=$sfiles->getAllbyStory($storyid);
        if(
count($filesarr)>0) {
            
$upl_tray = new XoopsFormElementTray(_AM_UPLOAD_ATTACHFILE,'<br />');
            
$upl_checkbox=new XoopsFormCheckBox('''delupload[]');

            foreach (
$filesarr as $onefile)
            {
                
$link sprintf("<a href='%s/%s' target='_blank'>%s</a>n",XOOPS_UPLOAD_URL,$onefile->getDownloadname('S'),$onefile->getFileRealName('S'));
                
$upl_checkbox->addOption($onefile->getFileid(),$link);
            }
            
$upl_tray->addElement($upl_checkbox,false);
            
$dellabel=new XoopsFormLabel(_AM_DELETE_SELFILES,'');
            
$upl_tray->addElement($dellabel,false);
            
$sform->addElement($upl_tray);
        }
    }
    
$sform->addElement(new XoopsFormFile(_AM_SELFILE'attachedfile'$xoopsModuleConfig['maxuploadsize']), false);
}


$option_tray = new XoopsFormElementTray(_OPTIONS,'<br />');
//Set date of publish/expiration
if ($approveprivilege) {
    if(
is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->getVar('mid'))) {
        
$approve=1;
    }
    
$approve_checkbox = new XoopsFormCheckBox('''approve'$approve);
    
$approve_checkbox->addOption(1_AM_APPROVE);
    
$option_tray->addElement($approve_checkbox);

    
$check=$published>:0;
    
$published_checkbox = new XoopsFormCheckBox('''autodate',$check);
    
$published_checkbox->addOption(1_AM_SETDATETIME);
    
$option_tray->addElement($published_checkbox);

    
$option_tray->addElement(new XoopsFormDateTime(_AM_SETDATETIME'publish_date'15$published));

    
$check=$expired>:0;
    
$expired_checkbox = new XoopsFormCheckBox('''autoexpdate',$check);
    
$expired_checkbox->addOption(1_AM_SETEXPDATETIME);
    
$option_tray->addElement($expired_checkbox);

    
$option_tray->addElement(new XoopsFormDateTime(_AM_SETEXPDATETIME'expiry_date'15$expired));
  
// ajout irishcofee
  
$sform->addElement(new XoopsFormText(_NW_TITLE'price'5255$price), true);
  
//fin // ajout irishcofee
   //blueteen - events - begin
    
$check=$booked>:0;
    
$booked_checkbox = new XoopsFormCheckBox('''autobookdate',$check);
    
$booked_checkbox->addOption(1_AM_course_SETEVENTDATETIME);
    
$option_tray->addElement($booked_checkbox);

    
$option_tray->addElement(new XoopsFormDateTime(_AM_course_SETEVENTDATETIME_BEGIN'booked_date'15$booked));//date de début de l'évènement
    
$option_tray->addElement(new XoopsFormDateTime(_AM_course_SETEVENTDATETIME_END'bookedend_date'15$bookedend));//date de fin de l'évènement
    //blueteen - events - end
}

if (
is_object($xoopsUser)) {
    
$notify_checkbox = new XoopsFormCheckBox('''notifypub'$notifypub);
    
$notify_checkbox->addOption(1_NW_NOTIFYPUBLISH);
    
$option_tray->addElement($notify_checkbox);
    if (
$xoopsUser->isAdmin($xoopsModule->getVar('mid'))) {
        
$nohtml_checkbox = new XoopsFormCheckBox('''nohtml'$nohtml);
        
$nohtml_checkbox->addOption(1_DISABLEHTML);
        
$option_tray->addElement($nohtml_checkbox);
    }
}
$smiley_checkbox = new XoopsFormCheckBox('''nosmiley'$nosmiley);
$smiley_checkbox->addOption(1_DISABLESMILEY);
$option_tray->addElement($smiley_checkbox);


$sform->addElement($option_tray);

//TODO: Approve checkbox + "Move to top" if editing + Edit indicator

//Submit buttons
$button_tray = new XoopsFormElementTray('' ,'');
$preview_btn = new XoopsFormButton('''preview'_PREVIEW'submit');
$preview_btn->setExtra('accesskey="p"');
$button_tray->addElement($preview_btn);
$submit_btn = new XoopsFormButton('''post'_NW_POST'submit');
$submit_btn->setExtra('accesskey="s"');
$button_tray->addElement($submit_btn);
$sform->addElement($button_tray);

//Hidden variables
if(isset($storyid)){
    
$sform->addElement(new XoopsFormHidden('storyid'$storyid));
}

if (!isset(
$returnside)) {
    
$returnside=isset($_POST['returnside']) ? intval($_POST['returnside']) : 0;
    if(empty(
$returnside))    {
        
$returnside=isset($_GET['returnside']) ? intval($_GET['returnside']) : 0;
    }
}

if(!isset(
$returnside)) {
    
$returnside=0;
}
$sform->addElement(new XoopsFormHidden('returnside'$returnside),false);

if (!isset(
$type)) {
    if (
$approveprivilege) {
        
$type "admin";
    }
    else {
        
$type "user";
    }
}
$type_hidden = new XoopsFormHidden('type'$type);
$sform->addElement($type_hidden);
$sform->display();
?>

Posté le : 30/11/2009 12:47
Partager Twitter Partagez cette article sur GG+
Re: Ajouter un champ au module News
Régulier
Inscrit: 22/03/2006 10:49
Messages: 197
up ;)

Posté le : 02/12/2009 14:10
Partager Twitter Partagez cette article sur GG+
Re: Ajouter un champ au module News
Xoops accro
Inscrit: 20/02/2008 20:27
De Belgium
Messages: 2708
Citation :
J'ai donc d'abord ajouté un nouveau champ à la table stories qui s'appelle "prix" et qui est en fin de table.

je les mets ici à suivre (ctrl+F "price" pour retrouver toutes les modifs)
Et pourquoi ce nom différent?

Posté le : 02/12/2009 14:48

Salutations, Gerard.
PS: Excusez mon mauvais français.
De la bonne manière de poser les questions
Partager Twitter Partagez cette article sur GG+
Re: Ajouter un champ au module News
Régulier
Inscrit: 22/03/2006 10:49
Messages: 197
Autant pour moi, le nom de la table est bien "price". ce nom est le seul utilisé.

Posté le : 05/12/2009 10:07
Partager Twitter Partagez cette article sur GG+

 Haut   Précédent   Suivant
(1) 2 »



Vous pouvez voir les sujets.
Vous ne pouvez pas débuter de nouveaux sujets.
Vous ne pouvez pas répondre aux contributions.
Vous ne pouvez pas éditer vos contributions.
Vous ne pouvez pas effacez vos contributions.
Vous ne pouvez pas ajouter de nouveaux sondages.
Vous ne pouvez pas voter en sondage.
Vous ne pouvez pas attacher des fichiers à vos contributions.
Vous ne pouvez pas poster sans approbation.

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

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