<?php
/**
 * @package linea21.modules
 * @subpackage workshop
 * @author linea21 <info@linea21.com>
 * @version $id SVN
 * @access public
 * @license http://opensource.org/licenses/gpl-3.0.html
 */

themeInclude('../workshop/'.SQL.'.inc.php');

/**
 * DisplayUrlAllCalendar()
 * affichage de l'URL de détails d'un calendrier
 * @param $workshop_id
 * @return
 **/
function DisplayUrlAllCalendar($workshop_id) {
  $link_table= array('rub'=> $GLOBALS['links'][LANGUAGE]['calendar']['linkvalue'],'id'=>$workshop_id);
  $content='<p>'.END_LINE;
  $content.='<a href="'.HrefMaker($link_table).'" title="'.formatText(_t('workshop','cal_all'), '2ATT').'">'._t('workshop','cal_all').'</a>'.END_LINE;
  $content.='</p>'.END_LINE;
  echo $content;
}

/**
 * DisplayUrlInscription()
 * affichage de l'URL d'inscription au groupe de travail
 * @param $workshop_id
 * @param $testcookie
 * @return
 **/
function DisplayUrlInscription($workshop_id, $testcookie) {
  $link_table= array('rub'=> $GLOBALS['links'][LANGUAGE]['subscribe-workgroup']['linkvalue'],'id'=>$workshop_id);
  $link_table2= array('rub'=> $GLOBALS['links'][LANGUAGE]['user-prefs']['linkvalue']);

  if (!isset($_COOKIE['linea21'])) {
    $content='<div class="info">'._t('divers','noauth').''.END_LINE;
    $content.='<br />'._t('divers','creaauth').' : '.END_LINE;
    $content.='<a href="'.HrefMaker($link_table2).'" title="'.formatText(_t('divers','auth'), '2ATT').'" >'._t('divers','auth').'</a>'.END_LINE;
    $content.='</div>'.END_LINE;
  }
  else{
    if ($testcookie<>true) {
      $content='<div class="info">'._t('workshop','noinscription').''.END_LINE;
      $content.='<br />'._t('workshop','creainscription2').' : '.END_LINE;
      $content.='<a href="'.HrefMaker($link_table).'" title="'.formatText(_t('workshop','creainscription'), '2ATT').'" onclick="return window.confirm(\''._t('workshop','creainscription3').'\')" >'._t('workshop','creainscription').'</a></div>'.END_LINE;
    }
  }
  echo $content;
}

/**
 * DisplayUrlTopicList()
 * affichage URL pour accéder aux discussions
 * @param $work_id
 * @param $contenu
 * @return
 **/
function DisplayUrlTopicList($work_id, $work_name) {
  $link_table= array('rub'=> $GLOBALS['links'][LANGUAGE]['topic-list']['linkvalue'],'id'=>$work_id, 'name' => $work_name);
  $content='<a href="'.HrefMaker($link_table).'" title="'.formatText(_t('workshop','com_public'), '2ATT').'" id="barre_discussion" >'._t('workshop','com_public').'</a>'.END_LINE;
  echo $content;
}
/**
 * DisplayUrlCalendar()
 * affichage URL pour accéder aux calendrier
 * @param $work_id
 * @param $contenu
 * @return
 **/
function DisplayUrlCalendar($work_id, $work_name) {
  $link_table= array('rub'=> $GLOBALS['links'][LANGUAGE]['calendar']['linkvalue'],'id'=>$work_id, 'name' => $work_name);
  $content='<a href="'.HrefMaker($link_table).'" title="'.formatText(_t('workshop','cal_all'), '2ATT').'" id="barre_calendar" >'._t('workshop','cal_all').'</a>'.END_LINE;
  echo $content;
}
/**
 * DisplayUrlListerapport()
 * affichage URL pour accéder aux rapports
 * @param $work_id
 * @param $contenu
 * @return
 **/
function DisplayUrlListerapport($work_id, $work_name) {
  $link_table= array('rub'=> $GLOBALS['links'][LANGUAGE]['report-all']['linkvalue'],'id'=>$work_id, 'name' => $work_name);
  $content='<a href="'.HrefMaker($link_table).'" title="'.formatText(_t('workshop','barre_report'), '2ATT').'" id="barre_report" >'._t('workshop','barre_report').'</a>'.END_LINE;
  echo $content;
}
/**
 * DisplayUrlListeutilisateurs()
 * affichage URL pour accéder aux utilisatuers
 * @param $work_id
 * @param $contenu
 * @return
 **/
function DisplayUrlListeutilisateur($work_id, $work_name) {
  $link_table= array('rub'=> $GLOBALS['links'][LANGUAGE]['user-all']['linkvalue'],'id'=>$work_id, 'name' => $work_name);
  $content='<a href="'.HrefMaker($link_table).'" title="'.formatText(_t('workshop','barre_user'), '2ATT').'" id="barre_user" >'._t('workshop','barre_user').'</a>'.END_LINE;
  echo $content;
}
function DisplayUrlAddTopic($work_id) {
  $link_table= array('rub'=> $GLOBALS['links'][LANGUAGE]['topic-add']['linkvalue'],'id'=>$work_id);
  $content='<a href="'.HrefMaker($link_table).'" title="'.formatText(_t('workshop','add_com'), '2ATT').'" class="add_topic">'._t('workshop','add_com').'</a>'.END_LINE;
  echo $content;
}

/**
 * DisplayListWorkshop()
 * affichage de la liste de groupe de travail
 * @param integer $id_filter
 * @param integer $filter
 * @return
 **/
function DisplayListWorkshop($id_filter=-1, $filter=-1) {

  if ($filter=="") $filter='public';
  $data=$GLOBALS['sql_object'] -> DBSelect(SQL_getWorkshopList($debut=-1, $limite=-1, $filter , $id_filter));

  if($data!=0)
  {
    $content= '';
    for($i=0; $i<count($data); $i++) {
      $link_table= array('rub'=> $GLOBALS['links'][LANGUAGE]['workgroup']['linkvalue'],'id'=>$data[$i]['workshop_id'],'name'=>$data[$i]['workshop_denomination']);
      $link_table2= array('rub'=> $GLOBALS['links'][LANGUAGE]['workgroup']['linkvalue'],'filter'=> $GLOBALS['filters'][LANGUAGE]['theme']['linkvalue'],'id'=>$data[$i]['sdtheme_id'], 'name'=>$data[$i]['sdtheme_name']);
      $link_table3= array('rub'=> $GLOBALS['links'][LANGUAGE]['workgroup']['linkvalue'],'filter'=> $GLOBALS['filters'][LANGUAGE]['level']['linkvalue'],'id'=>$data[$i]['workshop_level'], 'name'=>$data[$i]['level_name']);
      $workshop_title=formatText($data[$i]['workshop_denomination'], '2HTML');
      $workshop_resume=formatText(cutText($data[$i]['workshop_resume'],500), '2HTML');
      $workshop_sdtheme=formatText($data[$i]['sdtheme_name'], '2HTML');
      $workshop_level=formatText($data[$i]['level_name'], '2HTML');
       
      $content.='<h2><a href="'.HrefMaker($link_table).'" title="'.formatText($workshop_title, '2ATT').'">'.$workshop_title.'</a>'.END_LINE;
      $content.='</h2>'.END_LINE;
      $content.='<p>'.$workshop_resume.'</p>'.END_LINE;
      $content.='<p class="filter_info">'._t('divers','level').' : <a href="'.HrefMaker($link_table3).'" title="'.formatText($workshop_level, '2ATT').'" class="filter_info_level" >'.$workshop_level.'</a> '.END_LINE;
      $content.=' '._t('divers','themeref').': <a href="'.HrefMaker($link_table2).'" title="'.formatText($workshop_sdtheme, '2ATT').'" class="filter_info_theme">'.$workshop_sdtheme.'</a></p>'.END_LINE;
      $content.='<hr />'.END_LINE;
    }
  }
  else
  {
    $content='<p class="info">'._t('divers','nodata').'</p>';
  }

  echo $content;
}
/**
 * DisplayCalendar()
 * affichage du calendrier
 * @param $workshop_id
 * @param $nb
 * @return
 **/
function DisplayCalendar($workshop_id) {
  $data=$GLOBALS['sql_object'] -> DBSelect(SQL_getoneListCalWorkshop($workshop_id, "ALL"));
  $content = ''.END_LINE;
  if($data!=0)
  {
    $datenow= strtotime("now");
    $inter=1*24*3600;

    for($i=0; $i<count($data); $i++) {

      $workcal_title=formatText($data[$i]['workcal_task'], '2HTML');
      $workcal_resume=formatText($data[$i]['workcal_task_details'], '2HTML');
      $workcal_author=formatText($data[$i]['user_login'], '2HTML');
      $workcal_date_publi=formatText($data[$i]['workcal_task_date_display'], '2HTML');
      $link_table= array('rub'=> $GLOBALS['links'][LANGUAGE]['user-profile']['linkvalue'],'id'=>$data[$i]['workcal_posted_by'], 'name'=>$data[$i]['workcal_task']);
       
      $datetask=$data[$i]['workcal_task_date_display'];
       
      $datetask=explode("-", $datetask);
      $jour = $datetask[0];
      $mois = $datetask[1];
      $annee = $datetask[2];
      $datetask2 = mktime (0, 0, 0, $mois, $jour, $annee);

      if (($datetask2+$inter)>$datenow){
         
        $content.='<div class="task_in_date"><p>'.$workcal_date_publi.'</p>';
        $content.='<a href="'.HrefMaker($link_table).'" title="'.formatText($workcal_author, '2ATT').'">'.$workcal_author.'</a></div>';
        $content.='<div class="task_in"><h3>'.$workcal_title.'</h3>'.END_LINE;
      }
      else {
        $content.='<div class="task_out_date"><p>'.$workcal_date_publi.'</p>';
        $content.='<a href="'.HrefMaker($link_table).'" title="'.formatText($workcal_author, '2ATT').'">'.$workcal_author.'</a></div>';
        $content.='<div class="task_out"><h3>'.$workcal_title.'</h3>'.END_LINE;
      }
      $content.='<p>'.$workcal_resume.'</p></div>'.END_LINE;
    }
  }
  else
  {
    $content.='<p class="info">'._t('divers','nodata').'</p>';
  }

  echo $content;
}

/**
 * DisplayOneWorkshop()
 * affichage du détail d'un groupe de travail
 * @param $workshop_id
 * @param integer $title
 * @return
 **/
function DisplayOneWorkshop($workshop_id, $title=-1) {
  $data=$GLOBALS['sql_object'] -> DBSelect(SQL_getoneCompleteWorkshop($workshop_id));
  $content = ''.END_LINE;
  if($data!=0)
  {
    for($i=0; $i<count($data); $i++) {

      $link_self= array('rub'=> $GLOBALS['links'][LANGUAGE]['workgroup']['linkvalue'],'id'=>$workshop_id);
      $link_table2= array('rub'=> $GLOBALS['links'][LANGUAGE]['workgroup']['linkvalue'],'filter'=> $GLOBALS['filters'][LANGUAGE]['theme']['linkvalue'],'id'=>$data[$i]['sdtheme_id'], 'name'=>$data[$i]['sdtheme_name']);
      $link_table3= array('rub'=> $GLOBALS['links'][LANGUAGE]['workgroup']['linkvalue'],'filter'=> $GLOBALS['filters'][LANGUAGE]['level']['linkvalue'],'id'=>$data[$i]['workshop_level'], 'name'=>$data[$i]['level_name']);
      $workshop_title=formatText($data[$i]['workshop_denomination'], '2HTML');
      $workshop_resume=formatText($data[$i]['workshop_resume'], '2HTML');
      //$workshop_comment=formatText(cutText($data[$i]['workshop_comment'],150), '2HTML');
      $workshop_sdtheme=formatText($data[$i]['sdtheme_name'], '2HTML');
      $workshop_theme=formatText(cutText($data[$i]['theme_name'],50), '2HTML');
      $workshop_level=formatText($data[$i]['level_name'], '2HTML');
       
       
      if ($title<>-1) {
        $content.='<h1 class="nobottommargin">'.$workshop_title.'</h1>'.END_LINE;
      }
      else{
        $content.='<p class="permalink">'.END_LINE;
        $content.= formatted_permalink($link_self);
        $content.='</p>'.END_LINE;
        //$content.='<h2>'._t('workshop','det').'</h2>'.END_LINE;
        $content.='<p class="h1_comment_bg" id="workshop_det">'.$workshop_resume.'</p>'.END_LINE;
        //$content.='<p>'.$workshop_comment.'</p>'.END_LINE;
        $content.='<p class="filter_info">'._t('divers','level').' : <a href="'.HrefMaker($link_table3).'" title="'.formatText($workshop_level, '2ATT').'" class="filter_info_level" >'.$workshop_level.'</a> '.END_LINE;
        $content.=' '._t('divers','themeref').' : <a href="'.HrefMaker($link_table2).'" title="'.formatText($workshop_sdtheme, '2ATT').'" class="filter_info_theme" >'.$workshop_sdtheme.'</a></p> '.END_LINE;
        //._t('divers','sousthemeref').':'.$workshop_theme.'</p>'.END_LINE;
      }
    }
  }
  else
  {
    $content.='<p class="info">'._t('divers','nodata').'</p>';
  }

  echo $content;
}

/**
 * DisplayUserWorkshop()
 * affichage des utilisateurs/organisateurs d'un groupe de travail
 * @param $workshop_id
 * @return
 **/
function DisplayUserWorkshop($workshop_id) {
  $data=$GLOBALS['sql_object'] -> DBSelect(SQL_getWorkshopUserList($workshop_id));
  $content1='<p>'._t('workshop','organizer2').' :';
  $content2='<p>'._t('workshop','user').' :';
  if($data!=0)
  {
    for($i=0; $i<count($data); $i++) {

      $workcal_author=formatText($data[$i]['user_login'], '2HTML');
      $link_table= array('rub'=> $GLOBALS['links'][LANGUAGE]['user-profile']['linkvalue'],'id'=>$data[$i]['jwu_user_id'], 'name'=>$data[$i]['user_login']);
       
      if($data[$i]['jwu_user_right']<>"U") $content1.=' <a href="'.HrefMaker($link_table).'" title="'.formatText($workcal_author, '2ATT').'">'.$workcal_author.'</a> '.END_LINE;
      else $content2.=' <a href="'.HrefMaker($link_table).'" title="'.formatText($workcal_author, '2ATT').'">'.$workcal_author.'</a> '.END_LINE;
    }
    $content1.='</p>'.END_LINE;
    $content2.='</p>'.END_LINE;
    $content=$content1.$content2;
  }
  else
  {
    $content.='<p class="info">'._t('workshop','no_user').'</p>';
  }
  echo $content;
}

/**
 * DisplayListReport()
 * affichage de la liste des rapports d'un groupe de travail
 * @param $workshop_id
 * @return
 **/
function DisplayListReport($workshop_id) {
  $data=$GLOBALS['sql_object'] -> DBSelect(SQL_getWorkshopReportList($workshop_id,"P"));
  $content = ''.END_LINE;
  if($data!=0)
  {
    for($i=0; $i<count($data); $i++) {

      $link_table= array('rub'=> $GLOBALS['links'][LANGUAGE]['report']['linkvalue'],'id'=>$data[$i]['workrep_id'], 'name'=>$data[$i]['workrep_title']);
      $workrep_title=formatText($data[$i]['workrep_title'], '2HTML');
      $workrep_resume=formatText(cutText($data[$i]['workrep_resume'],200), '2HTML');
      $workrep_date_publi=formatText($data[$i]['workrep_published_date'], '2HTML');
      $content.='<h3><a href="'.HrefMaker($link_table).'" title="'.formatText($workrep_title, '2ATT').'">'.$workrep_title.'</a></h3>'.END_LINE;
      $content.='<p>'.$workrep_resume.'</p>'.END_LINE;
      $content.='<p class="filter_info">'._t('workshop','date_report').' : <span>'.$workrep_date_publi.'</span></p>'.END_LINE;
      $content.='<hr />'.END_LINE;
    }
  }
  else
  {
    $content.='<p class="info">'._t('workshop','no_report').'</p>';
  }
  echo $content;
}

/**
 * DisplayListTopic()
 * affichage de la liste des discussions
 * @param $workshop_id
 * @param $debut
 * @return
 **/
function DisplayListTopic($workshop_id, $debut) {

  $result_workcom_list=$GLOBALS['sql_object'] -> DBSelect(SQL_getWorkcomList($debut, SELECT_LIMIT, $workshop_id));
  $result_nb_com=$GLOBALS['sql_object'] -> DBSelect(SQL_getcountnbcom($workshop_id));
  $bdd_nb_com=$result_nb_com[0]['num_rows'];


  $table_link=array('rub' => $GLOBALS['links'][LANGUAGE]['topic-list']['linkvalue'],'id' => $workshop_id);
  echo $bdd_nb_com_display = "<p class=\"nb_sujet\">".$bdd_nb_com." "._t('workshop','nb_total_com')."</p>\n";
  if($result_workcom_list!=0) {

    $content= "<table cellspacing=\"1\" cellpadding=\"3\" class=\"table_discussion\" summary=\""._t('workshop','com')."\">".END_LINE;
    $content.= "<thead>\n";
    $content.= "<tr>\n";
    $content.= "<td>"._t('divers','statut')."</td>".END_LINE;
    $content.= "<td>"._t('workshop','com_subject')."</td>".END_LINE;
    $content.= "<td>"._t('workshop','com_author')."</td>".END_LINE;
    $content.= "<td>"._t('workshop','com_nb_rep')."</td>".END_LINE;
    $content.= "<td>"._t('workshop','com_date_last')."</td>".END_LINE;
    $content.= "</tr>".END_LINE;
    $content.= "</thead>".END_LINE;
    $content.= "<tbody>".END_LINE;


    for($i=0; $i<count($result_workcom_list); $i++) {

      $result_workcom_det=$GLOBALS['sql_object'] -> DBSelect(SQL_getWorkcom_detList($result_workcom_list[$i]['workcom_id']));
      $link_user= array('rub'=> $GLOBALS['links'][LANGUAGE]['user-profile']['linkvalue'],'id'=>$result_workcom_list[$i]['workcom_user_id'], 'name' => $result_workcom_list[$i]['user_login']);
      $link_det_com= array('rub'=> $GLOBALS['links'][LANGUAGE]['topic']['linkvalue'],'id'=>$result_workcom_list[$i]['workcom_id'], 'parentid' => $workshop_id, 'name' => $result_workcom_list[$i]['workcom_subject']);

      $workcom_title=formatText(cutText($result_workcom_list[$i]['workcom_subject'], 70, 1), '2HTML');
      $workcom_user=formatText(cutText($result_workcom_list[$i]['user_login'], 10, 1), '2HTML');


      $content.= "<tr>".END_LINE;
      if ($result_workcom_list[$i]['workcom_statut']=='C') {
        $content.= "<td><img src=\"" .THEME_PUBLIC_PATH. "images/ico_lock_dis.gif\" alt=\"\" /></td>".END_LINE;
      }
      else $content.= "<td>&nbsp;</td>\n";
      $content.= "<td style=\"width:50%\"><a href=\"".HrefMaker($link_det_com)."\" title=\"".formatText($workcom_title, '2ATT')."\" class=\"table_title\">".$workcom_title."</a></td>".END_LINE;
      $content.= "<td><a href=\"".HrefMaker($link_user)."\" title=\"".formatText($workcom_user, '2ATT')."\" class=\"table_auth\">".$workcom_user."</a></td>".END_LINE;
      if ($result_workcom_det[0]['nb_rep']=="") {
        $content.= "<td>0</td>".END_LINE;
      }
      else $content.= "<td style=\"width:11%\">".$result_workcom_det[0]['nb_rep']."</td>".END_LINE;
      if ($result_workcom_det[0]['workcom_date_crea_display']=="") {
        $content.= "<td>".$result_workcom_list[$i]['workcom_date_crea_display']."</td>".END_LINE;
      }
      else
      $content.= "<td>".$result_workcom_list[$i]['workcom_date_crea_display']."</td>".END_LINE;
      $content.= "</tr>".END_LINE;
    }

    $content.= "</tbody>".END_LINE;
    $content.= "</table>".END_LINE;
  }else {
    $content= '<p class="info">'._t('workshop','no_com').'</p>'.END_LINE;
  }
  DisplayUrlAddTopic($workshop_id);
  Display_linkin_page($table_link, $bdd_nb_com, $debut);
  echo $content;
  Display_linkin_page($table_link, $bdd_nb_com, $debut);
  DisplayUrlAddTopic($workshop_id);
}

/**
 * DisplayTopic()
 * affichage d'une discussion
 * @param $workshop_id
 * @param $topic_id
 * @param $debut
 * @param $flash
 * @param $post_id
 * @return
 **/
function DisplayTopic($workshop_id, $topic_id, $debut) {

  $dataroot=$GLOBALS['sql_object'] -> DBSelect(SQL_getOnetopicWorkcom($workshop_id, $topic_id, $topic_id));
  $topic_state=$dataroot[0]['workcom_statut'];
  $result_display="";

  $data=$GLOBALS['sql_object'] -> DBSelect(SQL_getOnetopicWorkcom2($workshop_id, $topic_id, $root= -1, $debut, SELECT_LIMIT));
  $result_nb_com=$GLOBALS['sql_object'] -> DBSelect(SQL_getWorkcom_detList($topic_id));
  $bdd_nb_com=$result_nb_com[0]['nb_rep'];


  $table_link=array('rub' => $GLOBALS['links'][LANGUAGE]['topic']['linkvalue'],'id' => $topic_id, 'parentid' => $workshop_id, 'name' => $dataroot[0]['workcom_subject'] );

  $post_title=formatText($dataroot[0]['workcom_subject'], '2HTML');
  $post_body=formatText($dataroot[0]['workcom_body'], '2HTML');
  $post_user=formatText(cutText($dataroot[0]['user_login'], 10, 1), '2HTML');

   
  $content= '';
  echo "<p class=\"nb_sujet\">".$bdd_nb_com_display = $bdd_nb_com." "._t('workshop','nb_total_com_mes')."</p>".END_LINE;
  echo'<h2>'._t('workshop','com_name').' : '.$post_title.'</h2>'.END_LINE;
  echo Display_linkin_page($table_link, $bdd_nb_com, $debut);
  echo '<hr />'.END_LINE;

  if ($debut==0) {

    $complete_uri='../'.$dataroot[0]['profile_avatar'];
    if($dataroot[0]['profile_avatar'] == "") $user_profile_avatar='<img src="'.THEME_PUBLIC_PATH.'/images/no_avatar.png" alt="'.formatText($dataroot[0]['user_login'], '2HTML').'" class="user_profile"/>';
    else $user_profile_avatar='<img src="'.$complete_uri.'" alt="'. formatText($dataroot[0]['user_login'], '2HTML').'" class="user_profile"/>';
    
    $link_user= array('rub'=> $GLOBALS['links'][LANGUAGE]['user-profile']['linkvalue'],'id'=>$dataroot[0]['workcom_user_id'], 'name' => $dataroot[0]['user_login']);
    $content.='<div class="blocksujet">'.END_LINE;
    $content.='<p class="workshop_auth_sujet">'.$user_profile_avatar.'<a href="'.HrefMaker($link_user).'" title="'.formatText($post_user, '2ATT').'">'.$post_user.'</a></p>'.END_LINE;
    $content.='<h3>'.$post_title.'</h3>'.END_LINE;
    $content.='<p>'.$post_body.'</p>'.END_LINE;
    $content.='<p class="workshop_date_sujet">'._t('workshop','com_date_publi').' : <span>'.$dataroot[0]['workcom_date_crea_display'].'</span></p>'.END_LINE;
    $content.='</div>'.END_LINE;
    $content.='<hr />'.END_LINE;
  }


  if($data!=0)
  {

    for($i=0; $i<count($data); $i++) {
       
      $post_title=formatText($data[$i]['workcom_subject'], '2HTML');
      $post_body=formatText($data[$i]['workcom_body'], '2HTML');
      $post_user=formatText(cutText($data[$i]['user_login'], 10, 1), '2HTML');
      $post_id=$data[$i]['workcom_id'];
      $link_user= array('rub'=> $GLOBALS['links'][LANGUAGE]['user-profile']['linkvalue'],'id'=>$data[$i]['workcom_user_id'], 'name'=> $data[$i]['user_login']);
      $link_edit= array('rub'=> $GLOBALS['links'][LANGUAGE]['post-update']['linkvalue'],'parentid'=>$workshop_id, 'id'=>$data[$i]['workcom_id'], 'parentparentid'=>$topic_id, 'name'=> $data[$i]['workcom_subject']);
      $complete_uri='../'.$data[$i]['profile_avatar'];
      if($data[$i]['profile_avatar'] == "") $user_profile_avatar='<img src="'.THEME_PUBLIC_PATH.'/images/no_avatar.png" alt="'. formatText($data[$i]['user_login'], '2HTML').'" class="user_profile"/>';
      else $user_profile_avatar='<img src="'.$complete_uri.'" alt="'. formatText($data[$i]['user_login'], '2HTML').'" class="user_profile"/>';
   
      if(isset($_COOKIE['linea21']['id'])) {
        if ($data[$i]['workcom_user_id']==$_COOKIE['linea21']['id'] && $topic_state == 'P') {
          $edit='<a href="'.HrefMaker($link_edit).'" title="'.formatText(_t('workshop','mod_com_mes'), '2ATT').'">'._t('workshop','mod_com_mes').'</a>'.END_LINE;
        }else $edit='';
      }
      $content.='<div class="blocksujet" id="'.$post_id.'">'.END_LINE;
      $content.='<p class="workshop_auth_sujet">'.$user_profile_avatar.'<a href="'.HrefMaker($link_user).'" title="'.formatText($post_user, '2ATT').'">'.$post_user.'</a></p>'.END_LINE;
      $content.='<h3>'.$post_title.'</h3>'.END_LINE;
      $content.='<p>'.$post_body.'</p>'.END_LINE;
      $content.=' <p class="workshop_date_sujet">'.$edit.' '._t('workshop','com_date_publi').' : <span>'.$data[$i]['workcom_date_crea_display'].'</span></p>'.END_LINE;
      //$content.=$edit;
      $content.='</div>'.END_LINE;
      $content.='<hr />'.END_LINE;
    }
  }
  else
  {
    $content.='<p class="info">'._t('workshop','no_com_rep').'</p>';
  }

  echo $content;
  echo Display_linkin_page($table_link, $bdd_nb_com, $debut);
  if ($topic_state=="P")  echo GetFormAddPost($workshop_id, $topic_id);
  else echo $content='<p class="info">'._t('workshop','com_p_lock').'</p>';
}


/**
 * AddTopic
 * Ajout d'une discussion
 * @param $workshop_id
 * @param $debut
 * @param $body
 * @param $title
 * @param $confirm
 */
function AddTopic($workshop_id, $debut, $body, $title, $confirm_update)
{
  if(!$confirm_update)  echo GetFormAddTopic($workshop_id);
  else
  {
    //test new value for this post in form
    $integrity=CheckComIntegrity($title, $body);
    if($integrity  == 1)
    {
      $topic_id=AddPersistentPost($title, $body, '', $workshop_id);
      echo '<p class="confirm">'._t('workshop','confirm_add_com').'</p>'.END_LINE;
      //scroll jusque $post_id
      echo DisplayListTopic($workshop_id, $debut);
    }
    else
    {
      echo "<p class=\"error\">".$integrity."</p>";
      echo GetFormAddTopic($workshop_id, $body, $title);
    }
  }
}

/**
 * AddPost
 * Ajout d'un Message
 * @param $workshop_id
 * @param $topic_id
 * @param $debut
 * @param $body
 * @param $title
 */
function AddPost($workshop_id, $topic_id, $debut, $body, $title)
{
  $dataroot=$GLOBALS['sql_object'] -> DBSelect(SQL_getOnetopicWorkcom($workshop_id, $topic_id, $topic_id));
  $topic_state=$dataroot[0]['workcom_statut'];
  if ($topic_state<>"P")  DisplayTopic($workshop_id, $topic_id, $debut);
  else {
    $integrity=CheckComIntegrity($title, $body);
    if($integrity  == 1)
    {
      $post_id=AddPersistentPost($title, $body, $topic_id, $workshop_id);
      echo '<p class="confirm">'._t('workshop','confirm_add_com').'</p>'.END_LINE;
      //scroll jusque $post_id
      echo DisplayTopic($workshop_id, $topic_id, $debut);
    }
    else
    {
      echo "<p class=\"error\">".$integrity."</p>";
      echo GetFormAddPost($workshop_id, $topic_id, $body, $title);
    }
  }
}

/**
 * UpdatePost
 * Mise à jour d'un message
 * @param $workshop_id
 * @param $topic_id
 * @param $debut
 * @param $new_body
 * @param $new_title
 * @param $post_id
 * @param $confirm_update
 * @return void
 */
function UpdatePost($workshop_id, $topic_id, $debut, $new_body, $new_title, $post_id, $confirm_update)
{
  $data=$GLOBALS['sql_object'] -> DBSelect(SQL_getOnetopicWorkcom($workshop_id, $post_id, "root"));
  $old_title=formatText($data[0]['workcom_subject'], '2FIELD');
  $old_body=formatText($data[0]['workcom_body'], '2FIELD');
  $topic_state=$data[0]['workcom_statut'];

  if ($topic_state<>"P")  DisplayTopic($workshop_id, $topic_id, $debut);
  else {
    //display old value for this post in form
    if(!$confirm_update)  echo GetFormModPost($workshop_id, $topic_id, $post_id, $old_body, $old_title);
    else
    {
      //test new value for this post in form
      $integrity=CheckComIntegrity($new_title, $new_body);
      if($integrity  == 1)
      {
        $post_id=ModPersistentPost($new_title, $new_body, $post_id, $workshop_id, $topic_id);
        echo '<p class="confirm">'._t('workshop','confirm_mod_com').'</p>'.END_LINE;
        //scroll jusque $post_id
        echo DisplayTopic($workshop_id, $topic_id, $debut);
      }
      else
      {
        echo "<p class=\"error\">".$integrity."</p>";
        echo GetFormModPost($workshop_id, $topic_id, $post_id, $old_body, $old_title);
      }
    }
  }
}


/**
 * GetFormAddTopic()
 * formulaire d'ajout d'un Topic
 * @param $workshop_id
 * @param $subject_body
 * @param $subject_title
 * @return
 **/
function GetFormAddTopic($workshop_id, $body='', $title='') {

  $form='<h2>'._t('workshop','add_com').'</h2>'.END_LINE;
  $form.='<form action="index.php" method="post">'.END_LINE;
  $form.='<div id="reponse">'.END_LINE;
  $form.='<label for="title">'._t('workshop','com_subject').' : </label>'.END_LINE;
  $form.='<input type="text" maxlength="50"  name="title" id="title" value="'.$title.'" class="textfield" />'.END_LINE;
  $form.='<label for="body">'._t('workshop','com_body').' : </label>'.END_LINE;
  $form.='<textarea id="body" name="body" rows="12" cols="20" class="textfield">'.$body.'</textarea>'.END_LINE;
  $form.='<input type="hidden" value="'.$GLOBALS['links'][LANGUAGE]['topic-add']['linkvalue'].'" name="rub" id="rub" />'.END_LINE;
  $form.='<input type="hidden" value="'.$workshop_id.'" name="id" id="id" />'.END_LINE;
  $form.='<input type="hidden" value="true" name="confirm" id="confirm" />'.END_LINE;
  $form.='<br /><input type="submit" value="'._t('btn','valid').'" name="valider" id="valider" />'.END_LINE;
  $form.='</div>'.END_LINE;
  $form.='</form>'.END_LINE;
  return $form;

}

/**
 * GetFormModPost()
 * formulaire de modification d'un Post
 * @param $workshop_id
 * @param $topic_id
 * @param integer $post_id
 * @param $subject_body
 * @param $subject_title
 * @return
 **/
function GetFormModPost($workshop_id, $topic_id, $post_id, $body, $title) {

  $form='<h2>'._t('workshop','mod_com_mes').'</h2>'.END_LINE;
  $form.='<form action="index.php" method="post">'.END_LINE;
  $form.='<div id="reponse">'.END_LINE;
  $form.='<label for="title">'._t('workshop','com_subject').' : </label>'.END_LINE;
  $form.='<input type="text" maxlength="50"  name="title" id="title" value="'.$title.'" class="textfield" />'.END_LINE;
  $form.='<label for="body">'._t('workshop','com_body').' : </label>'.END_LINE;
  $form.='<textarea id="body" name="body" rows="12" cols="20" class="textfield">'.$body.'</textarea>'.END_LINE;
  $form.='<input type="hidden" value="'.$GLOBALS['links'][LANGUAGE]['post-update']['linkvalue'].'" name="rub" id="rub" />'.END_LINE;
  $form.='<input type="hidden" value="'.$workshop_id.'" name="parentid" id="parentid" />'.END_LINE;
  $form.='<input type="hidden" value="'.$post_id.'" name="id" id="id" />'.END_LINE;
  $form.='<input type="hidden" value="true" name="confirm" id="confirm" />'.END_LINE;
  $form.='<input type="hidden" value="'.$topic_id.'" name="parentparentid" id="parentparentid" />'.END_LINE;
  $form.='<br /><input type="submit" value="'._t('btn','valid').'" name="valider" id="valider" />'.END_LINE;
  $form.='</div>'.END_LINE;
  $form.='</form>'.END_LINE;
  return $form;

}
/**
 * GetFormAddPost()
 * formulaire d'ajout d'un Post
 * @param $workshop_id
 * @param $topic_id
 * @param $body
 * @param $title
 * @return
 **/
function GetFormAddPost($workshop_id, $topic_id, $body='', $title=''){

  $form='<h2>'._t('workshop','add_com_mes').'</h2>'.END_LINE;
  $form.='<form action="index.php" method="post">'.END_LINE;
  $form.='<div id="reponse">'.END_LINE;
  $form.='<label for="title">'._t('workshop','com_subject').' : </label>'.END_LINE;
  $form.='<input type="text" maxlength="50"  name="title" id="title" value="'.$title.'"  class="textfield"  />'.END_LINE;
  $form.='<label for="body">'._t('workshop','com_body').' : </label>'.END_LINE;
  $form.='<textarea id="body" name="body" rows="12" cols="20" class="textfield">'.$body.'</textarea>'.END_LINE;
  $form.='<input type="hidden" value="'.$GLOBALS['links'][LANGUAGE]['post-add']['linkvalue'].'" name="rub" id="rub" />'.END_LINE;
  $form.='<input type="hidden" value="'.$topic_id.'" name="id" id="id" />'.END_LINE;
  $form.='<input type="hidden" value="'.$workshop_id.'" name="parentid" id="parentid" /><br />'.END_LINE;
  $form.='<input type="submit" alt="'._t('btn','valid').'" value="'._t('btn','valid').'" name="valider" id="valider" />'.END_LINE;
  $form.='</div>'.END_LINE;
  $form.='</form>'.END_LINE;
  return $form;
}

/**
 * CheckComIntegrity()
 * Vérification de l'intégrité des données
 * @param $title
 * @param $body
 * @param $workshop_com_object
 * @return
 **/
function CheckComIntegrity($title, $body){
  $integrity=1;
  if (strlen($title) < 3) $integrity=_t('workshop','com_no_subject');
  if (strlen($body) < 3) $integrity=_t('workshop','com_no_body');
  if(is_string($integrity)) return $integrity;
  else return 1;
}

/**
 * AddPersistentPost()
 * Ajout dans la base d'un nouveau Post
 * @param $title
 * @param $body
 * @param $topic_id
 * @param $workshop_id
 * @return
 **/
function AddPersistentPost($title, $body, $topic_id, $workshop_id){

  if(isset($_COOKIE['linea21']['id'])) {
    $user_id=$_COOKIE['linea21']['id'];

    include_once('../class/class.workshop_com.php');
    $workshop_com_object = new workshop_com;

    $result=CheckComIntegrity($title, $body);
    if ($result==1) {
      $table[0] = $title;
      $table[1] = $body;
      $table[2] = $topic_id;
      $table[3] = $user_id;
      $table[4] = $workshop_id;

      $result=$workshop_com_object->AddCom($table , $GLOBALS['sql_object']);
      return $result;
    }
    else return $result;
  } else return "<p class=\"error\">"._t('divers','errorauth')."</p>";
}

/**
 * ModPersistentPost()
 * Modification dans la base d'un Post
 * @param $title
 * @param $body
 * @param $mes_id
 * @param $workshop_id
 * @param $topic_id
 * @return
 **/
function ModPersistentPost($title, $body, $mes_id, $workshop_id, $topic_id){

  if(isset($_COOKIE['linea21']['id'])) {
    $user_id=$_COOKIE['linea21']['id'];
    include_once('../class/class.workshop_com.php');
    $workshop_com_object = new workshop_com;

    $result=CheckComIntegrity($title, $body);
    if ($result==1) {
      $table[0] = $title;
      $table[1] = $body;
      $result=$workshop_com_object->ModifyComUser($mes_id, $table , $user_id, $GLOBALS['sql_object']);

      if (!is_string($result)) return 1;
      else return $result;
    }
    else return $result;
  } else return "<p class=\"error\">"._t('divers','errorauth')."</p>";
}


/**
 * DisplayConfirmInscription()
 * affichage de la confirmation d'inscription
 * @param $link
 * @return
 **/
function DisplayConfirmInscription($link) {
  $content='<p class="confirm">'._t('workshop','confirm_inscription').' <a href="'.$link.'" title="'._t('workshop','com_p_back_com').'" >'._t('workshop','com_p_back_com').'</a>'.END_LINE;
  $content.='</p>'.END_LINE;
  echo $content;
}


/**
 * DisplayInscription()
 * inscription d'un utilisateur au groupe de travail + affichage du résultat
 * @param $workshop_id
 * @return
 **/
function DisplayInscription($workshop_id){
  if(isset($_COOKIE['linea21']['login'])) {
    $login=$_COOKIE['linea21']['login'];
    include_once('../class/class.workshop.php');
    $workshop_object = new workshop;
    $result=$workshop_object->AddUserWorkshop($workshop_id, $login , "U", $GLOBALS['sql_object']);
    if (is_numeric($result)) {
      $link=HrefMaker(array('rub'=>$GLOBALS['links'][LANGUAGE]['discussion']['linkvalue'], 'id'=>$workshop_id));
      UpdateCookieWorkshop($workshop_id);
      echo DisplayConfirmInscription($link);
    }
    else echo $result;
  } else echo "<p class=\"error\">"._t('divers','errorauth')."</p>";
}
?>