dokeos-announcements
[ class tree: dokeos-announcements ] [ index: dokeos-announcements ] [ all elements ]

Source for file announcements.php

Documentation is available at announcements.php

  1. <?php //$Id: announcements.php 15535 2008-06-10 17:29:54Z juliomontoya $
  2. /*
  3. ==============================================================================
  4.     Dokeos - elearning and course management software
  5.  
  6.     Copyright (c) 2004-2008 Dokeos SPRL
  7.     Copyright (c) 2003 Ghent University (UGent)
  8.     Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9.     Copyright (c) various contributors
  10.  
  11.     For a full list of contributors, see "credits.txt".
  12.     The full license can be read in "license.txt".
  13.  
  14.     This program is free software; you can redistribute it and/or
  15.     modify it under the terms of the GNU General Public License
  16.     as published by the Free Software Foundation; either version 2
  17.     of the License, or (at your option) any later version.
  18.  
  19.     See the GNU General Public License for more details.
  20.  
  21.     Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  22.     Mail: info@dokeos.com
  23. ==============================================================================
  24. */
  25. /**
  26. ==============================================================================
  27.  * @author Frederik Vermeire <frederik.vermeire@pandora.be>, UGent Internship
  28.  * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: code cleaning
  29.  * @abstract The task of the internship was to integrate the 'send messages to specific users' with the
  30.  *              Announcements tool and also add the resource linker here. The database also needed refactoring
  31.  *              as there was no title field (the title was merged into the content field)
  32.  * @package dokeos.announcements
  33.  * @todo make AWACS out of the configuration settings
  34.  * @todo this file is 1200+ lines without any functions -> needs to be split into
  35.  *  multiple functions
  36. ==============================================================================
  37. */
  38. /*
  39. ==============================================================================
  40.         INIT SECTION
  41. ==============================================================================
  42. */
  43. // name of the language file that needs to be included
  44. $language_file['announcements';
  45. $language_file['group';
  46. $language_file['survey';
  47.  
  48. // use anonymous mode when accessing this course tool
  49. $use_anonymous true;
  50.  
  51. // setting the global file that gets the general configuration, the databases, the languages, ...
  52. include('../inc/global.inc.php');
  53. $this_section=SECTION_COURSES;
  54.  
  55. $nameTools get_lang('Announcement');
  56.  
  57.  
  58. //session
  59. if(isset($_GET['id_session']))
  60.     $_SESSION['id_session'$_GET['id_session'];
  61.  
  62. /* ------------    ACCESS RIGHTS ------------ */
  63. // notice for unauthorized people.
  64.  
  65. /*
  66. -----------------------------------------------------------
  67.     Constants and variables
  68. -----------------------------------------------------------
  69. */
  70. // Configuration settings
  71. $display_announcement_list true;
  72. $display_form             false;
  73. $display_title_list          true;
  74.  
  75. // Maximum title messages to display
  76. $maximum     '12';
  77.  
  78. // Length of the titles
  79. $length     '36';
  80.  
  81. // Database Table Definitions
  82. $tbl_course_user           Database::get_main_table(TABLE_MAIN_COURSE_USER);
  83. $tbl_user                  Database::get_main_table(TABLE_MAIN_USER);
  84. $tbl_courses            Database::get_main_table(TABLE_MAIN_COURSE);
  85. $tbl_sessions            Database::get_main_table(TABLE_MAIN_SESSION);
  86. $tbl_group                 Database::get_course_table(TABLE_GROUP);
  87. $tbl_groupUser          Database::get_course_table(TABLE_GROUP_USER);
  88. $tbl_announcement        Database::get_course_table(TABLE_ANNOUNCEMENT);
  89. $tbl_item_property      Database::get_course_table(TABLE_ITEM_PROPERTY);
  90.  
  91. /*
  92. -----------------------------------------------------------
  93.     Resource linker
  94. -----------------------------------------------------------
  95. */
  96. $_SESSION['source_type']="Ad_Valvas";
  97. include('../resourcelinker/resourcelinker.inc.php');
  98.  
  99. if (!empty($_POST['addresources'])) // When the "Add Resource" button is clicked we store all the form data into a session
  100. {
  101.     include('announcements.inc.php');
  102.  
  103.     $form_elementsarray ('emailTitle'=>stripslashes($emailTitle)'newContent'=>stripslashes($newContent)'id'=>$id'to'=>$selectedform'emailoption'=>$email_ann);
  104.     $_SESSION['formelements']=$form_elements;
  105.  
  106.     if($id// this is to correctly handle edits
  107.     {
  108.           $action="edit";
  109.     }else
  110.     {
  111.           $action="add";
  112.     }
  113.  
  114.     // ============== //
  115.     // 7 = Ad_Valvas    //
  116.     // ============== //
  117.     if($surveyid)
  118.     {
  119.         header("Location: ../resourcelinker/resourcelinker.php?source_id=7&action=$action&id=$id&originalresource=no&publish_survey=$surveyid&db_name=$db_name&cidReq=$cidReq");
  120.         exit;
  121.     }
  122.     else
  123.     {
  124.         header("Location: ../resourcelinker/resourcelinker.php?source_id=7&action=$action&id=$id&originalresource=no");
  125.         exit;
  126.     }
  127.     exit;
  128. }
  129.  
  130. /*
  131. -----------------------------------------------------------
  132.     Tracking
  133. -----------------------------------------------------------
  134. */
  135. include(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  136.  
  137. /*
  138. -----------------------------------------------------------
  139.     Libraries
  140. -----------------------------------------------------------
  141. */
  142. require_once(api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  143. require_once('announcements.inc.php');
  144. require_once(api_get_path(INCLUDE_PATH).'lib/mail.lib.inc.php');
  145. require_once(api_get_path(INCLUDE_PATH).'conf/mail.conf.php');
  146. require_once(api_get_path(LIBRARY_PATH).'debug.lib.inc.php');
  147. require_once(api_get_path(LIBRARY_PATH).'tracking.lib.php');
  148.  
  149. /*
  150. -----------------------------------------------------------
  151.     POST TO
  152. -----------------------------------------------------------
  153. */
  154. if (!empty($_POST['To']))
  155. {
  156.     $display_form true;
  157.  
  158.     $form_elementsarray ('emailTitle'=>$_POST['emailTitle']'newContent'=>$_POST['newContent']'id'=>$_POST['id']'emailoption'=>$_POST['email_ann']);
  159.     $_SESSION['formelements']=$form_elements;
  160.  
  161.     $form_elements                $_SESSION['formelements'];
  162.  
  163.     $title_to_modify            $form_elements["emailTitle"];
  164.  
  165.     $content_to_modify          $form_elements["newContent"];
  166.  
  167.     $announcement_to_modify     $form_elements["id"];
  168. }
  169.  
  170. /*
  171. -----------------------------------------------------------
  172.     Show/hide user/group form
  173. -----------------------------------------------------------
  174. */
  175.  
  176. $setting_select_groupusers=true;
  177. if (empty($_POST['To']and !$_SESSION['select_groupusers'])
  178. {
  179.     $_SESSION['select_groupusers']="hide";
  180. }
  181. $select_groupusers_status=$_SESSION['select_groupusers'];
  182. if (!empty($_POST['To']and ($select_groupusers_status=="hide"))
  183. {
  184.     $_SESSION['select_groupusers']="show";
  185. }
  186. if (!empty($_POST['To']and ($select_groupusers_status=="show"))
  187. {
  188.     $_SESSION['select_groupusers']="hide";
  189. }
  190.  
  191. /*
  192. -----------------------------------------------------------
  193.     Action handling
  194. -----------------------------------------------------------
  195. */
  196.  
  197. // display the form
  198. if (((!empty($_GET['action']&& $_GET['action'== 'add'&& $_GET['origin'== ""|| (!empty($_GET['action']&& $_GET['action'== 'edit'|| !empty($_POST['To']))
  199. {
  200.     $display_form true;
  201. }
  202.  
  203. // clear all resources
  204. if ((empty($originalresource|| ($originalresource!=='no')) and (!empty($action&& $action=='add'))
  205. {
  206.     $_SESSION['formelements']=null;
  207.     //unset($_SESSION['formelements']);
  208. }
  209.  
  210. /*
  211. -----------------------------------------------------------
  212.     Javascript
  213. -----------------------------------------------------------
  214. */
  215.  
  216. $htmlHeadXtra[to_javascript();
  217.  
  218. /*
  219. -----------------------------------------------------------
  220.     Filter user/group
  221. -----------------------------------------------------------
  222. */
  223.  
  224. if(!empty($_GET['toolgroup'])){
  225.     if($_GET['toolgroup'== strval(intval($_GET['toolgroup'])))//check is integer
  226.         $toolgroup $_GET['toolgroup'];
  227.         $_SESSION['select_groupusers''hide';
  228.     }else{
  229.         $toolgroup 0;
  230.     }
  231.     api_session_register("toolgroup");
  232. }
  233.  
  234.  
  235. /*
  236. -----------------------------------------------------------
  237.     Sessions
  238. -----------------------------------------------------------
  239. */
  240. if (!empty($_SESSION['formelements']and !empty($_GET['originalresource']and $_GET['originalresource'== 'no')
  241. {
  242.     $form_elements            $_SESSION['formelements'];
  243.     $title_to_modify        $form_elements['emailTitle'];
  244.     $content_to_modify        $form_elements['newContent'];
  245.     $announcement_to_modify    $form_elements['id'];
  246.     $to                        $form_elements['to'];
  247.     //load_edit_users('announcement',$announcement_to_modify);
  248.  
  249.     $email_ann                $form_elements['emailoption'];
  250. }
  251. if(!empty($_GET['remind_inactive']))
  252. {
  253.     $to['USER:'.intval($_GET['remind_inactive']);
  254. }
  255. /*
  256. -----------------------------------------------------------
  257.     Survey
  258. -----------------------------------------------------------
  259. */
  260. $surveyid 0;
  261. if(!empty($_REQUEST['publish_survey']))
  262. {
  263.     $surveyid=Database::escape_string($_REQUEST['publish_survey']);
  264. }
  265. $cidReq=Database::escape_string($_REQUEST['cidReq']);
  266. if($surveyid)
  267. {
  268.     $db_name=Database::escape_string($_REQUEST['db_name']);
  269.     $sql_temp "SELECT * FROM $db_name.survey WHERE survey_id='$surveyid'";
  270.     $res_temp api_sql_query($sql_temp__FILE____LINE__);
  271.     $obj=@Database::fetch_object($res_temp);
  272.     $template=$obj->template;
  273. }
  274. if($surveyid)
  275. {
  276.     $interbreadcrumb[array ("url" => "../survey/survey_list.php?cidReq=$cidReq""name" => get_lang('Survey'));
  277.     $nameTools get_lang('PublishSurvey');
  278. }
  279. else
  280. $nameTools get_lang('Announcement');
  281.  
  282. $nameTools12 get_lang('PublishSurvey');
  283.  
  284.  
  285.  
  286. /*
  287. -----------------------------------------------------------
  288.     Learning path & css
  289. -----------------------------------------------------------
  290. */
  291. // showing the header if we are not in the learning path, if we are in
  292. // the learning path, we do not include the banner so we have to explicitly
  293. // include the stylesheet, which is normally done in the header
  294. if (empty($_GET['origin']or $_GET['origin'!== 'learnpath')
  295. {
  296.     //we are not in the learning path
  297.     Display::Display_header($nameTools,"Announcements");
  298. }
  299. else
  300. {
  301.     //we are in the learning path, only display central data and change css
  302.     $display_title_list false;
  303.     $display_announcement_list false;
  304.     $display_specific_announcement true;
  305.     $announcement_id $_REQUEST['ann_id'];
  306.     ?> <link rel="stylesheet" type="text/css" href="<?php echo $clarolineRepositoryWeb ?>css/default.css">
  307.     <!-- css file for announcements -->
  308.     <link href="../css/announcements.css" rel="stylesheet" type="text/css">
  309.     <?php
  310. }
  311.  
  312. // inserting an anchor (top) so one can jump back to the top of the page
  313. echo "<a name=\"top\"></a>";
  314.  
  315. /*=============================================
  316.               ACTION HANDLING
  317. =============================================*/
  318.  
  319. if (api_is_allowed_to_edit(OR (api_get_course_setting('allow_user_edit_announcement'&& !api_is_anonymous()))
  320. {
  321.     /*
  322.     -----------------------------------------------------------
  323.         Change visibility of announcement
  324.     -----------------------------------------------------------
  325.     */
  326.     // $_GET['isStudentView']<>"false" is added to prevent that the visibility
  327.     // is changed after you do the following:
  328.     // change visibility -> studentview -> course manager view
  329.     if (isset($_GET['isStudentView']&& $_GET['isStudentView']!='false')
  330.     {
  331.         if (isset($_GET['id']AND $_GET['id'AND isset($_GET['action']AND $_GET['action']=="showhide")
  332.         {
  333.             $id=intval(addslashes($_GET['id']));
  334.             change_visibility(TOOL_ANNOUNCEMENT,$id);
  335.             $message get_lang("Visible");
  336.         }
  337.     }
  338.  
  339.     /*
  340.     -----------------------------------------------------------
  341.         Delete announcement
  342.     -----------------------------------------------------------
  343.     */
  344.     if (!empty($_GET['action']AND $_GET['action']=='delete' AND isset($_GET['id']))
  345.     {
  346.         //api_sql_query("DELETE FROM  $tbl_announcement WHERE id='$delete'",__FILE__,__LINE__);
  347.         $id=intval(addslashes($_GET['id']));
  348.  
  349.         // tooledit : visibility = 2 : only visibile for platform administrator
  350.         api_sql_query("UPDATE $tbl_item_property SET visibility='2' WHERE tool='".TOOL_ANNOUNCEMENT."' and ref='".$id."'",__FILE__,__LINE__);
  351.  
  352.         delete_added_resource("Ad_Valvas"$delete);
  353.  
  354.         $id null;
  355.         $emailTitle null;
  356.         $newContent null;
  357.  
  358.         $message get_lang("AnnouncementDeleted");
  359.     }
  360.  
  361.     /*
  362.     -----------------------------------------------------------
  363.         Delete all announcements
  364.     -----------------------------------------------------------
  365.     */
  366.     if (!empty($_GET['action']and $_GET['action']=='delete_all')
  367.     {
  368.  
  369.         //api_sql_query("DELETE FROM $tbl_announcement",__FILE__,__LINE__);
  370.  
  371.         api_sql_query("UPDATE $tbl_item_property SET visibility='2' WHERE tool='".TOOL_ANNOUNCEMENT."'",__FILE__,__LINE__);
  372.  
  373.         delete_all_resources_type("Ad_Valvas");
  374.  
  375.         $id null;
  376.         $emailTitle null;
  377.         $newContent null;
  378.  
  379.         $message get_lang("AnnouncementDeletedAll");
  380.     }
  381.  
  382.     /*
  383.     -----------------------------------------------------------
  384.         Modify announcement
  385.     -----------------------------------------------------------
  386.     */
  387.     if (!empty($_GET['action']and $_GET['action']=='modify' AND isset($_GET['id']))
  388.     {
  389.         $display_form true;
  390.  
  391.         // RETRIEVE THE CONTENT OF THE ANNOUNCEMENT TO MODIFY
  392.         $id intval(addslashes($_GET['id']));
  393.         $sql="SELECT * FROM  $tbl_announcement WHERE id='$id'";
  394.         $result api_sql_query($sql,__FILE__,__LINE__);
  395.         $myrow Database::fetch_array($result);
  396.  
  397.         if ($myrow)
  398.         {
  399.             $announcement_to_modify     $myrow['id'];
  400.             $content_to_modify         $myrow['content'];
  401.  
  402.             $title_to_modify             $myrow['title'];
  403.  
  404.             if ($originalresource!=="no"// and !addresources)
  405.             {
  406.                 //unset_session_resources();
  407.                 edit_added_resources("Ad_Valvas"$announcement_to_modify);
  408.                 $to=load_edit_users("announcement"$announcement_to_modify);
  409.             }
  410.  
  411.             $display_announcement_list false;
  412.         }
  413.  
  414.         if ($to=="everyone" OR !empty($_SESSION['toolgroup']))
  415.         {
  416.             $_SESSION['select_groupusers']="hide";
  417.         }
  418.         else
  419.         {
  420.             $_SESSION['select_groupusers']="show";
  421.         }
  422.  
  423.     }
  424.  
  425.     /*
  426.     -----------------------------------------------------------
  427.         Move announcement up/down
  428.     -----------------------------------------------------------
  429.     */
  430.     if (!empty($_GET['down']))
  431.     {
  432.         $thisAnnouncementId intval($_GET['down']);
  433.         $sortDirection "DESC";
  434.     }
  435.  
  436.     if (!empty($_GET['up']))
  437.     {
  438.         $thisAnnouncementId intval($_GET['up']);
  439.         $sortDirection "ASC";
  440.     }
  441.  
  442.     if (!empty($sortDirection))
  443.     {
  444.         if (!in_array(trim(strtoupper($sortDirection))array('ASC''DESC')))
  445.         {
  446.             $sortDirection='ASC';
  447.         }
  448.         $my_sql "SELECT announcement.id, announcement.display_order " .
  449.                 "FROM $tbl_announcement announcement, .
  450.                 "$tbl_item_property itemproperty .
  451.                 "WHERE itemproperty.ref=announcement.id " .
  452.                 "AND itemproperty.tool='".TOOL_ANNOUNCEMENT."' " .
  453.                 "AND itemproperty.visibility<>2 " .
  454.                 "ORDER BY display_order $sortDirection";
  455.         $result api_sql_query($my_sql,__FILE__,__LINE__);
  456.  
  457.         while (list ($announcementId$announcementOrderDatabase::fetch_row($result))
  458.         {
  459.             // STEP 2 : FOUND THE NEXT ANNOUNCEMENT ID AND ORDER.
  460.             //          COMMIT ORDER SWAP ON THE DB
  461.  
  462.             if (isset ($thisAnnouncementOrderFound&& $thisAnnouncementOrderFound == true)
  463.             {
  464.                 $nextAnnouncementId $announcementId;
  465.                 $nextAnnouncementOrder $announcementOrder;
  466.                 api_sql_query("UPDATE $tbl_announcement .
  467.                         "SET display_order = '$nextAnnouncementOrder.
  468.                         "WHERE id =  '$thisAnnouncementId'",__FILE__,__LINE__);
  469.                 api_sql_query("UPDATE $tbl_announcement .
  470.                         "SET display_order = '$thisAnnouncementOrder.
  471.                         "WHERE id =  '$nextAnnouncementId.'",__FILE__,__LINE__);
  472.  
  473.                 break;
  474.             }
  475.  
  476.             // STEP 1 : FIND THE ORDER OF THE ANNOUNCEMENT
  477.  
  478.             if ($announcementId == $thisAnnouncementId)
  479.             {
  480.                 $thisAnnouncementOrder $announcementOrder;
  481.                 $thisAnnouncementOrderFound true;
  482.             }
  483.         }
  484.         // show message
  485.         $message get_lang('AnnouncementMoved');
  486.     }
  487.  
  488.     /*
  489.     -----------------------------------------------------------
  490.         Submit announcement
  491.     -----------------------------------------------------------
  492.     */
  493.     if (api_is_allowed_to_edit(OR (api_get_course_setting('allow_user_edit_announcement'&& !api_is_anonymous()))
  494.     {
  495.  
  496.         $emailTitle=(!empty($_POST['emailTitle'])?$_POST['emailTitle']:'');
  497.         $newContent=(!empty($_POST['newContent'])?$_POST['newContent']:'');
  498.         $submitAnnouncement=isset($_POST['submitAnnouncement'])?$_POST['submitAnnouncement']:0;
  499.  
  500.         $id 0;
  501.         if(!empty($_POST['id']))
  502.         {
  503.             $id=intval($_POST['id']);
  504.         }
  505.  
  506.         if ($submitAnnouncement)
  507.         {
  508.             
  509.             if(isset($id)&&$id// there is an Id => the announcement already exists => update mode
  510.             {
  511.                 $edit_id edit_advalvas_item($id,$emailTitle,$newContent,$_POST['selectedform']);
  512.                 if(!$delete)
  513.                 {
  514.                     update_added_resources("Ad_Valvas"$id);
  515.                 }
  516.                 $message get_lang('AnnouncementModified');
  517.             }
  518.             else //insert mode
  519.             {
  520.                 if(!$surveyid){
  521.                     $result api_sql_query("SELECT MAX(display_order) FROM $tbl_announcement",__FILE__,__LINE__);
  522.     
  523.                     list($orderMaxDatabase::fetch_row($result);
  524.                     $order $orderMax 1;
  525.                     if(!empty($_SESSION['toolgroup'])){
  526.                         //$insert_id=store_advalvas_item($_POST['emailTitle'],$_POST['newContent'],$order,array('GROUP:'.$_SESSION['toolgroup']));
  527.                         $insert_id=store_advalvas_group_item($_POST['emailTitle'],$_POST['newContent'],$order,array('GROUP:'.$_SESSION['toolgroup']),$_POST['selectedform']);
  528.                     }else{
  529.                         $insert_id=store_advalvas_item($_POST['emailTitle'],$_POST['newContent'],$order,$_POST['selectedform']);
  530.                     }
  531.     
  532.                     store_resources($_SESSION['source_type'],$insert_id);
  533.     
  534.                     $_SESSION['select_groupusers']="hide";
  535.     
  536.                     $message get_lang('AnnouncementAdded');
  537.                 }
  538.  
  539. /*============================================================
  540. MAIL WHEN USER COMES FROM SURVEY
  541. ======================================================= */
  542.  
  543. if($_POST['emailsAdd'])
  544. {
  545.  
  546.      $to_email_address =$_POST['emailsAdd'];
  547.      $to_email_to explode(','$to_email_address);
  548.      $to_email array_unique($to_email_to);
  549.      $db_name $_REQUEST['db_name'];
  550.     for($i=0;$i<count($to_email);$i++)
  551.    {
  552.  
  553.             $totrim($to_email[$i]);
  554.             $db_name $_REQUEST['db_name'];
  555.             $newContentone=str_replace("#page#","choose_language.php",$newContent);
  556.             $newContenttwo=str_replace("#temp#",$template,$newContentone);
  557.             $newContentthree=str_replace("#sid#",$surveyid,$newContenttwo);
  558.             $newContentfour=str_replace("#mail#",$to,$newContentthree);
  559.             $newContentfive=str_replace("#db_name#",$db_name,$newContentfour);
  560.             $newContentsix=str_replace("#uid#","",$newContentfive);
  561.  
  562. if(eregi('^[0-9a-z_\.-]+@(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-z][0-9a-z-]*[0-9a-z]\.)+[a-z]{2,3})$'$to ))
  563. {
  564.      $subject=stripslashes($emailTitle);
  565.      $message=stripslashes($newContentsix);
  566.  
  567.     $sender_name $_SESSION['_user']['lastName'].' '.$_SESSION['_user']['firstName'];
  568.     $email $_SESSION['_user']['mail'];
  569.     $headers="From:$sender_name\r\nReply-to: $email\r\nContent-type: text/html; charset=iso-8859-15";
  570.     //@mail($to,$subject,$message,$headers);
  571.     //api_send_mail($to,$subject,$message,$headers);
  572.     api_mail('',$to,$subject,$message,$sender_name,$email,$headers);
  573.     $sql_date="SELECT * FROM $db_name.survey WHERE survey_id='$surveyid'";
  574.     $res_date=api_sql_query($sql_date__FILE____LINE__);
  575.     $obj_date=Database::fetch_object($res_date);
  576.     $end_date=$obj_date->avail_till;
  577.     $table_reminder Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER);
  578.     if($_REQUEST['reminder']=="1")
  579.     {
  580.         $time=getdate();
  581.         $time $time['yday'];
  582.         $time $time+7;
  583.         $sql_insert="INSERT INTO $table_reminder(sid,db_name,email,subject,content,reminder_choice,reminder_time,avail_till) values('$surveyid','$db_name','$to','".addslashes($subject)."','".addslashes($message)."','1','$time','$end_date')";
  584.         api_sql_query($sql_insert__FILE____LINE__);
  585.     }
  586.     else if($_REQUEST['reminder']=="2")
  587.     {
  588.         $time=getdate();
  589.         $time $time['yday'];
  590.         $time $time+14;
  591.         $sql_insert="INSERT INTO $table_reminder(sid,db_name,email,subject,content,reminder_choice,reminder_time,avail_till) values('$surveyid','$db_name','$to','".addslashes($subject)."','".addslashes($message)."','1','$time','$end_date')";
  592.         api_sql_query($sql_insert__FILE____LINE__);
  593.     }
  594.     else if($_REQUEST['reminder']=="3")
  595.     {
  596.         $time=getdate();
  597.         $time $time['yday'];
  598.         $time $time+30;
  599.         $sql_insert="INSERT INTO $table_reminder(sid,db_name,email,subject,content,reminder_choice,reminder_time,avail_till) values('$surveyid','$db_name','$to','".addslashes($subject)."','".addslashes($message)."','1','$time','$end_date')";
  600.         api_sql_query($sql_insert__FILE____LINE__);
  601.     }
  602.   }
  603.  }
  604. }
  605.  
  606.                 /*===================================================================
  607.                                                 MAIL FUNCTION
  608.                 ===================================================================*/
  609.  
  610.                 if ($_POST['email_ann'&& empty($_POST['onlyThoseMails']))
  611.                 {
  612.                     
  613.                       $sent_to=sent_to("announcement"$insert_id);
  614.                     
  615.                     $userlist   $sent_to['users'];
  616.                     $grouplist  $sent_to['groups'];
  617.  
  618.                         // groepen omzetten in users
  619.                         if ($grouplist)
  620.                         {
  621.  
  622.                             $grouplist "'".implode("', '",$grouplist)."'";    //protect individual elements with surrounding quotes
  623.                             $sql "SELECT user_id
  624.                                     FROM $tbl_groupUser gu
  625.                                     WHERE gu.group_id IN (".$grouplist.")";
  626.  
  627.  
  628.                             $groupMemberResult api_sql_query($sql,__FILE__,__LINE__);
  629.  
  630.  
  631.                             if ($groupMemberResult)
  632.                             {
  633.                                 while ($u Database::fetch_array($groupMemberResult))
  634.                                 {
  635.                                     $userlist [$u ['user_id']// complete the user id list ...
  636.                                 }
  637.                             }
  638.                         }
  639.  
  640.  
  641.                         if(is_array($userlist))
  642.                         {
  643.                             $userlist "'".implode("', '"array_unique($userlist) )."'";
  644.  
  645.                             // send to the created 'userlist'
  646.                             $sqlmail "SELECT user_id, lastname, firstname, email
  647.                                                         FROM $tbl_user
  648.                                                         WHERE user_id IN (".$userlist.")";
  649.                         }
  650.                         else if(empty($_POST['not_selected_form']))
  651.                         {
  652.                             if(empty($_SESSION['id_session']|| api_get_setting('use_session_mode')=='false')
  653.                             {
  654.                                 // send to everybody
  655.                                 $sqlmail "SELECT user.user_id, user.email, user.lastname, user.firstname
  656.                                              FROM $tbl_course_user$tbl_user
  657.                                              WHERE course_code='".Database::escape_string($_course['sysCode'])."'
  658.                                              AND course_rel_user.user_id = user.user_id";
  659.                             }
  660.                             else
  661.                             {
  662.                                 $sqlmail "SELECT user.user_id, user.email, user.lastname, user.firstname
  663.                                              FROM $tbl_user
  664.                                              INNER JOIN $tbl_session_course_user
  665.                                                  ON $tbl_user.user_id = $tbl_session_course_user.id_user
  666.                                                 AND $tbl_session_course_user.course_code = '".$_course['id']."'
  667.                                                 AND $tbl_session_course_user.id_session = ".intval($_SESSION['id_session']);
  668.                                 
  669.                             }
  670.                         }
  671.  
  672.                         if($sqlmail!='')
  673.                         {
  674.                             $result api_sql_query($sqlmail,__FILE__,__LINE__);
  675.  
  676.                             /*=================================================================================
  677.                                                     send email one by one to avoid antispam
  678.                             =================================================================================*/
  679.  
  680.  
  681.                             while ($myrow Database::fetch_array($result))
  682.                             {
  683.                                 /*    Header : Bericht van uw lesgever - GES ($_cid)
  684.  
  685.                                       Body :   John Doe (prenom + nom) <john_doe@hotmail.com> (email)
  686.  
  687.                                                  Morgen geen les!! (emailTitle)
  688.  
  689.                                                  Morgen is er geen les, de les wordt geschrapt wegens vergadering (newContent)
  690.                                 */
  691.  
  692.                                 $emailsubjbericht api_is_allowed_to_edit(get_lang('professorMessage'get_lang('LearnerMessage');
  693.                                 $emailSubject $emailsubjbericht" - ".$_course['official_code'];
  694.                                 $emailSubject $emailTitle;
  695.  
  696.                                 $db_name Database::get_course_table(TABLE_MAIN_SURVEY);
  697.  
  698.                                 if($surveyid)
  699.                                 {
  700.                                     $newContentone=str_replace("#page#","choose_language.php",$newContent);
  701.                                     $newContenttwo=str_replace("#temp#",$template,$newContentone);
  702.                                     $newContentthree=str_replace("#sid#",$surveyid,$newContenttwo);
  703.                                     $newContentfour=str_replace("#mail#",$myrow["email"],$newContentthree);
  704.                                     $newContentfive=str_replace("#db_name#",$db_name,$newContentfour);
  705.                                     $newContentsix=str_replace("#uid#",$myrow["user_id"],$newContentfive);
  706.                                     $message=stripslashes($newContentsix);
  707.  
  708.                                     $sender_name $_SESSION['_user']['lastName'].' '.$_SESSION['_user']['firstName'];
  709.                                     $email $_SESSION['_user']['mail'];
  710.  
  711.  
  712.                                     $headers="From:$sender_name\r\nReply-to: $email\r\nContent-type: text/html; charset=iso-8859-15";
  713.                                     //@mail($myrow["email"],stripslashes($emailTitle),$message,$headers);
  714.                                     api_mail('',$myrow["email"],stripslashes($emailTitle),$message,$sender_name,$email);
  715.                                 }
  716.                                 else
  717.                                 {
  718.                                     $mail_body $myrow["lastname"]." ".$myrow["firstname"]." <".$myrow["email"]."><br /> \n\n".stripslashes($emailTitle)."<br />".trim(stripslashes($newContent))." <br /><br />-- <br />";
  719.                                     $mail_body .= $_user['firstName'].' '.$_user['lastName']." ";
  720.                                     $mail_body .= "<".$_user['mail'].">\n";
  721.                                     $mail_body .= $_course['official_code'].' '.$_course['name'];
  722.  
  723.                                     //set the charset and use it for the encoding of the email - small fix, not really clean (should check the content encoding origin first)
  724.                                     //here we use the encoding used for the webpage where the text is encoded (ISO-8859-1 in this case)
  725.  
  726.                                     //$to_email_address =$_POST['emailsAdd'];
  727.                                     //$mail_body;
  728.                                     $headers array();
  729.                                       if(empty($charset)){$charset='ISO-8859-1';}
  730.                                     $headers['Content-Type''text/html';
  731.                                     $headers['charset'$charset;
  732.                                     $mailid=$myrow["email"];
  733.  
  734.                                     $newmail api_mail_html($myrow["lastname"].' '.$myrow["firstname"]$myrow["email"]stripslashes($emailSubject)$mail_body$_SESSION['_user']['lastName'].' '.$_SESSION['_user']['firstName']$_SESSION['_user']['mail'],$headers);
  735.                                 }
  736.                                 
  737.                                 $sql_date="SELECT * FROM $db_name WHERE survey_id='$surveyid'";
  738.                                 $res_date=api_sql_query($sql_date__FILE____LINE__);
  739.                                 $obj_date=Database::fetch_object($res_date);
  740.                                 $end_date=$obj_date->avail_till;
  741.                                 $table_reminder Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER);
  742.                                 
  743.                                 if($_REQUEST['reminder']=="1")
  744.                                 {
  745.                                     $time=getdate();
  746.                                     $time $time['yday'];
  747.                                     $time $time+7;
  748.                                     $sql="INSERT INTO $table_reminder(sid,db_name,email,subject,content,reminder_choice,reminder_time,avail_till) values('$surveyid','$db_name','$mailid','".addslashes($emailSubject)."','".addslashes($mail_body)."','1','$time','$end_date')";
  749.                                     api_sql_query($sql__FILE____LINE__);
  750.                                 }
  751.                                 else if($_REQUEST['reminder']=="2")
  752.                                 {
  753.                                     $time=getdate();
  754.                                     $time $time['yday'];
  755.                                     $time $time+14;
  756.                                     $sql="INSERT INTO $table_reminder(sid,db_name,email,subject,content,reminder_choice,reminder_time,avail_till) values('$surveyid','$db_name','$mailid','".addslashes($emailSubject)."','".addslashes($mail_body)."','1','$time','$end_date')";
  757.                                     api_sql_query($sql__FILE____LINE__);
  758.  
  759.                                 }
  760.                                 else if($_REQUEST['reminder']=="3")
  761.                                 {
  762.                                     $time=getdate();
  763.                                     $time $time['yday'];
  764.                                     $time $time+30;
  765.                                     $sql="INSERT INTO $table_reminder(sid,db_name,email,subject,content,reminder_choice,reminder_time,avail_till) values('$surveyid','$db_name','$mailid','".addslashes($emailSubject)."','".addslashes($mail_body)."','1','$time','$end_date')";
  766.                                     api_sql_query($sql__FILE____LINE__);
  767.                                 }
  768.                             }
  769.                             update_mail_sent($insert_id);
  770.                             $message $added_and_sent;
  771.                         }
  772.  
  773.                     // $email_ann*/
  774.  
  775.                 }    // isset
  776.  
  777.  
  778.             // UNSET VARIABLES
  779.  
  780.                 unset_session_resources();
  781.                 unset($form_elements);
  782.                 $_SESSION['formelements']=null;
  783.  
  784.                 $newContent null;
  785.                 $emailTitle null;
  786.  
  787.                 unset($emailTitle);
  788.                 unset($newContent);
  789.                 unset($content_to_modify);
  790.                 unset($title_to_modify);
  791.  
  792.  
  793.  
  794. if($_REQUEST['publish_survey'])
  795. {
  796.  
  797.  $surveyid=$_REQUEST['surveyid'];
  798.  $cidReq $_REQUEST['cidReq'];
  799.  ?>
  800. <script>
  801.     window.location.href="../survey/survey_list.php?<?php echo  api_get_cidreq()?>&published=published&surveyid=<?php echo $_REQUEST['publish_survey']?>";
  802. </script>
  803. <?php
  804. }
  805.  
  806.     }    // if $submit Announcement
  807.  
  808.  
  809.  
  810.  
  811.  
  812.   }
  813.  
  814. }
  815.  
  816. /*====================================================
  817.                      Tool Title
  818. ====================================================*/
  819. if (empty($_GET['origin']|| $_GET['origin'!== 'learnpath')
  820. {
  821.     //api_display_tool_title($nameTools);
  822. }
  823.  
  824. /*
  825. ==============================================================================
  826.         MAIN SECTION
  827. ==============================================================================
  828. */
  829.  
  830. /*=====================================================================================
  831.                                           MAIN CODE     HTML
  832. =====================================================================================*/
  833.  
  834.     // The commands below will change these display settings if they need it
  835.  
  836.  
  837.         if (empty($_GET['origin']OR $_GET['origin'!== 'learnpath')
  838.         {
  839.             echo "\n\n<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
  840.             echo "\t<tr>\n";
  841.  
  842.             echo "\t\t<td width=\"20%\" valign=\"top\">\n";
  843.         }
  844.       /*======================================================================
  845.                               DISPLAY LEFT COLUMN
  846.       ======================================================================*/
  847.         if(api_is_allowed_to_edit(OR (api_get_course_setting('allow_user_edit_announcement'&& !api_is_anonymous()) ) // check teacher status
  848.         {
  849.               if (empty($_GET['origin']or $_GET['origin'!== 'learnpath')
  850.                 {
  851.  
  852.                     $sql="SELECT
  853.                             announcement.*, toolitemproperties.*
  854.                             FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  855.                             WHERE announcement.id = toolitemproperties.ref
  856.                             AND toolitemproperties.tool='announcement'
  857.                             AND toolitemproperties.visibility<>'2'
  858.                             GROUP BY toolitemproperties.ref
  859.                             ORDER BY display_order DESC
  860.                             LIMIT 0,$maximum";
  861.                 }
  862.         }
  863.         else     // students only get to see the visible announcements
  864.         {
  865.             if (empty($_GET['origin']or $_GET['origin'!== 'learnpath')
  866.                 {
  867.                     $group_memberships=GroupManager::get_group_ids($_course['dbName']$_user['user_id']);
  868.  
  869.                     // the user is member of several groups => display personal announcements AND his group announcements AND the general announcements
  870.                     if (is_array($group_memberships&& count($group_memberships)>0)
  871.                     {
  872.                         $sql="SELECT
  873.                             announcement.*, toolitemproperties.*
  874.                             FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  875.                             WHERE announcement.id = toolitemproperties.ref
  876.                             AND toolitemproperties.tool='announcement'
  877.                             AND toolitemproperties.visibility='1'
  878.                             AND    ( toolitemproperties.to_user_id='".$_user['user_id']."'" .
  879.                                 "OR toolitemproperties.to_group_id IN (0, ".implode(", "$group_memberships).") )
  880.                             GROUP BY toolitemproperties.ref
  881.                             ORDER BY display_order DESC
  882.                             LIMIT 0,$maximum";
  883.                     }
  884.                     // the user is not member of any group
  885.                     else
  886.                     {
  887.                         // this is an identified user => show the general announcements AND his personal announcements
  888.                         if ($_user['user_id'])
  889.                         {
  890.                             $sql="SELECT
  891.                                 announcement.*, toolitemproperties.*
  892.                                 FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  893.                                 WHERE announcement.id = toolitemproperties.ref
  894.                                 AND toolitemproperties.tool='announcement'
  895.                                 AND toolitemproperties.visibility='1'
  896.                                 AND ( toolitemproperties.to_user_id='".$_user['user_id']."' OR toolitemproperties.to_group_id='0')
  897.                                 GROUP BY toolitemproperties.ref
  898.                                 ORDER BY display_order DESC
  899.                                 LIMIT 0,$maximum";
  900.                         }
  901.                         // the user is not identiefied => show only the general announcements
  902.                         else
  903.                         {
  904.                             $sql="SELECT
  905.                                 announcement.*, toolitemproperties.*
  906.                                 FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  907.                                 WHERE announcement.id = toolitemproperties.ref
  908.                                 AND toolitemproperties.tool='announcement'
  909.                                 AND toolitemproperties.visibility='1'
  910.                                 AND toolitemproperties.to_group_id='0'
  911.                                 GROUP BY toolitemproperties.ref
  912.                                 ORDER BY display_order DESC
  913.                                 LIMIT 0,$maximum";
  914.                         }
  915.                     }
  916.                 }
  917.         }
  918.  
  919.  
  920. $result api_sql_query($sql,__FILE__,__LINE__);
  921.  
  922. $announcement_number Database::num_rows($result);
  923.  
  924. /*----------------------------------------------------
  925.                 ADD ANNOUNCEMENT / DELETE ALL
  926. ----------------------------------------------------*/
  927. if(!$surveyid)
  928. {
  929.         if ((api_is_allowed_to_edit(OR (api_get_course_setting('allow_user_edit_announcement'&& !api_is_anonymous())) and (empty($_GET['origin']or $_GET['origin'!== 'learnpath'))
  930.         {
  931.  
  932.             echo "<a href='".api_get_self()."?".api_get_cidreq()."&action=add&origin=".(empty($_GET['origin'])?'':$_GET['origin'])."'><img src=\"../img/announce_add.gif\"> ".get_lang("AddAnnouncement")."</a><br/>";
  933.             
  934.         }
  935.         if (api_is_allowed_to_edit(&& $announcement_number 1)
  936.         {
  937.             echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=delete_all\" onclick=\"javascript:if(!confirm('".get_lang("ConfirmYourChoice")."')) return false;\"><img src=\"../img/valves_delete.gif\"/> ".get_lang("AnnouncementDeleteAll")."</a>\n";
  938.         }    // if announcementNumber > 1
  939.         echo "<hr noshade size=\"1\">";
  940. }
  941.  
  942. /*----------------------------------------------------
  943.                 ANNOUNCEMENTS LIST
  944. ----------------------------------------------------*/
  945. if(!$surveyid)
  946. {
  947.     
  948. if ($display_title_list == true)
  949. {
  950.     echo "\t\t\t<table>\n";
  951.     while ($myrow Database::fetch_array($result))
  952.     {
  953.             $title $myrow['title'];
  954.  
  955.             echo "\t\t\t\t<tr>\n";
  956.             echo "\t\t\t\t\t<td width=\"15%\">\n";
  957.             if ($myrow['visibility']==0)
  958.                 $class="class=\"invisible\"";}
  959.             else
  960.             $class="";}
  961.             echo "\t\t\t\t\t\t<a style=\"text-decoration:none\" href=\"announcements.php?".api_get_cidreq()."#".$myrow['id']."\" ".$class.">" api_trunc_str($title,$length"</a>\n";
  962.             echo "\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
  963.     }
  964.     echo "\t\t\t</table>\n";
  965. // end $display_title_list == true
  966. }
  967.  
  968. if (empty($_GET['origin']or $_GET['origin'!== 'learnpath')
  969. {
  970.     echo   "\t\t</td>\n";
  971.     echo "\t\t<td width=\"20\" background=\"../img/verticalruler.gif\">&nbsp;</td>\n";
  972.     // START RIGHT PART
  973.     echo    "\t\t<td valign=\"top\">\n";
  974. }
  975.  
  976. /*=======================================
  977.             DISPLAY ACTION MESSAGE
  978. =======================================*/
  979.  
  980. if (isset($message&& $message == true)
  981. {
  982.     Display::display_normal_message($message);
  983.     $display_announcement_list true;
  984.     $display_form             false;
  985. }
  986.  
  987. /*==================================================================================
  988.                                    DISPLAY FORM
  989. ==================================================================================*/
  990.  
  991.  
  992.     if ($display_form == true)
  993.     {
  994.         
  995.         $content_to_modify=stripslashes($content_to_modify);
  996.         $title_to_modify=stripslashes($title_to_modify);
  997.         
  998.         // DISPLAY ADD ANNOUNCEMENT COMMAND
  999.  
  1000.         echo "<form method=\"post\" name=\"f1\" action=\"".api_get_self()."?publish_survey=$surveyid&id=".$_GET['id']."&db_name=$db_name&cidReq=".$_GET['cidReq']."&action=".$_GET['action']."\" style=\"margin:0px;\">\n";
  1001.  
  1002.         //this variable defines if the course administrator can send a message to a specific user / group
  1003.         // or not
  1004.         //echo "sessiewaarde: ".$_SESSION['select_groupusers'];
  1005.     if(empty($_SESSION['toolgroup'])){
  1006.         
  1007.         echo "<table><tr><td>";
  1008.         echo get_lang("SentTo").": ";
  1009.         echo "</td><td>";
  1010.         if(isset($_GET['id']&& is_array($to)){
  1011.             echo '&nbsp;';
  1012.         }
  1013.         elseif(isset($_GET['remind_inactive']))
  1014.         {
  1015.             $email_ann '1';
  1016.             $_SESSION['select_groupusers']="show";
  1017.             $content_to_modify sprintf(get_lang('RemindInactiveLearnersMailContent'),api_get_setting('siteName')7);
  1018.             $title_to_modify sprintf(get_lang('RemindInactiveLearnersMailSubject'),api_get_setting('siteName'));
  1019.         }
  1020.         elseif(isset($_GET['remindallinactives']&& $_GET['remindallinactives']=='true')
  1021.         {
  1022.             $since = isset($_GET['since']intval($_GET['since']6;
  1023.             $to Tracking :: get_inactives_students_in_course($_course['id'],$since$_SESSION['id_session']);
  1024.             foreach($to as &$user)
  1025.             {
  1026.                 $user 'USER:'.$user;
  1027.             }
  1028.             $_SESSION['select_groupusers']="show";
  1029.             $email_ann '1';
  1030.             $content_to_modify sprintf(get_lang('RemindInactiveLearnersMailContent'),api_get_setting('siteName'),$since);
  1031.             $title_to_modify sprintf(get_lang('RemindInactiveLearnersMailSubject'),api_get_setting('siteName'));
  1032.             
  1033.             //echo '&nbsp;<script type="text/javascript">document.onload = "document.getElementById(\'recipient_list\').style.display=\'block\'";</script>';
  1034.         }
  1035.         else{
  1036.             echo get_lang("Everybody");
  1037.         }
  1038.         echo "</td><td>";
  1039.         echo '<a href="#" onclick="if(document.getElementById(\'recipient_list\').style.display==\'none\') document.getElementById(\'recipient_list\').style.display=\'block\'; else document.getElementById(\'recipient_list\').style.display=\'none\';">'.get_lang('ModifyRecipientList').'</span>';
  1040.         echo "</td></tr></table>";
  1041.         show_to_form($to);
  1042.  
  1043.         echo "<br /><br />";
  1044.  
  1045.         if (!isset($announcement_to_modify) ) $announcement_to_modify ="";
  1046.         if ($announcement_to_modify=='')
  1047.         {
  1048.             ($email_ann=='1')?$checked='checked':$checked='';
  1049.             echo "<input class=\"checkbox\" type=checkbox value=\"1\" name=\"email_ann\" $checked".get_lang('EmailOption')," : ",
  1050.             "<br /><br />";
  1051.         }
  1052.     }else{
  1053.             if (!isset($announcement_to_modify) ) $announcement_to_modify ="";
  1054.             if ($announcement_to_modify=='')
  1055.             {
  1056.                 ($email_ann=='1' || !empty($surveyid))?$checked='checked':$checked='';
  1057.                 echo "<input class=\"checkbox\" type=checkbox value=\"1\" name=\"email_ann\" $checked".get_lang('EmailOption')," : ".get_lang('MyGroup'),
  1058.                 "<br><br>";
  1059.                 echo '<a href="#" onclick="if(document.getElementById(\'recipient_list\').style.display==\'none\') document.getElementById(\'recipient_list\').style.display=\'block\'; else document.getElementById(\'recipient_list\').style.display=\'none\';">'.get_lang('ModifyRecipientList').'</a>';
  1060.                 
  1061.                 show_to_form_group($_SESSION['toolgroup']);
  1062.                 
  1063.                 echo '<br><br>';
  1064.             }
  1065.         }
  1066.         if($surveyid){
  1067.             echo    get_lang('EmailAddress').": <input type=\"text\" name=\"emailsAdd\" value=\"".$emails_add."\" size=\"52\">(Comma separated for multiple)<br>";
  1068.             echo    get_lang('OnlyThoseAddresses').": <input type=\"checkbox\" name=\"onlyThoseMails\"><br>";
  1069.         }
  1070.         echo    get_lang('EmailTitle').": <input type=\"text\" name=\"emailTitle\" value=\"".$title_to_modify."\" size=\"52\"><br />";
  1071.  
  1072.                 unset($title_to_modify);
  1073.                 $title_to_modify null;
  1074.  
  1075.  
  1076.         if (!isset($announcement_to_modify) ) $announcement_to_modify ="";
  1077.         if (!isset($content_to_modify) )         $content_to_modify ="";
  1078.         if (!isset($title_to_modify))         $title_to_modify "";
  1079.         
  1080.         echo    "<br />\n<input type=\"hidden\" name=\"id\" value=\"".$announcement_to_modify."\">";
  1081.         if($surveyid){
  1082.             $content_to_modify='<br /><a href="'.api_get_path(WEB_CODE_PATH).'/survey/#page#?temp=#temp#&surveyid=#sid#&uid=#uid#&mail=#mail#&db_name=#db_name">'.get_lang('ClickHereToOpenSurvey').'</a><br />
  1083.                                             '.get_lang('OrCopyPasteUrl').' <br />
  1084.                                             '.api_get_path(WEB_CODE_PATH).'/survey/#page#?temp=#temp#&surveyid=#sid#&uid=#uid#&mail=#mail#&db_name=#db_name&nbsp';
  1085.         }
  1086.                 //api_disp_html_area('newContent',$content_to_modify,'250px');
  1087.                 
  1088.                 require_once(api_get_path(LIBRARY_PATH"/fckeditor/fckeditor.php");
  1089.                 $oFCKeditor new FCKeditor('newContent';
  1090.                 $oFCKeditor->BasePath    api_get_path(WEB_PATH'main/inc/lib/fckeditor/' ;
  1091.                 $oFCKeditor->Height        '250';
  1092.                 $oFCKeditor->Width        '100%';
  1093.                 $oFCKeditor->Value        $content_to_modify;
  1094.                 $oFCKeditor->Config['CustomConfigurationsPath'api_get_path(REL_PATH)."main/inc/lib/fckeditor/myconfig.js";
  1095.                 $oFCKeditor->ToolbarSet "Announcements";
  1096.                 
  1097.                 $TBL_LANGUAGES Database::get_main_table(TABLE_MAIN_LANGUAGE);
  1098.                 $sql="SELECT isocode FROM ".$TBL_LANGUAGES." WHERE english_name='".$_SESSION["_course"]["language"]."'";
  1099.                 $result_sql=api_sql_query($sql__FILE____LINE__);
  1100.                 $isocode_language=Database::result($result_sql,0,0);
  1101.                 $oFCKeditor->Config['DefaultLanguage'$isocode_language;
  1102.                 
  1103.                 echo $oFCKeditor->CreateHtml();
  1104.  
  1105.                 if(empty($_SESSION['toolgroup'])){
  1106.                     echo '<br /><input type="Submit" name="submitAnnouncement" value="'.get_lang('Ok').'" onclick="selectAll(this.form.elements[3],true)" /><br /><br />';
  1107.                 }
  1108.                 else{
  1109.                     echo '<br /><input type="Submit" name="submitAnnouncement" value="'.get_lang('Ok').'" onclick="selectAll(this.form.elements[4],true)" /><br /><br />';
  1110.                 }
  1111.                 echo '</form><br />';
  1112.         if((isset($_GET['action']&& isset($_GET['id']&& is_array($to))||isset($_GET['remindallinactives'])||isset($_GET['remind_inactive'])){
  1113.             echo '<script>document.getElementById(\'recipient_list\').style.display=\'block\';</script>';
  1114.         }
  1115.     // displayform
  1116.  
  1117.  
  1118.  
  1119. /*===============================================
  1120.               DISPLAY ANNOUNCEMENT LIST
  1121. ===============================================*/
  1122.  
  1123.  
  1124.     if ($display_announcement_list && !$surveyid)
  1125.     {
  1126.         // by default we use the id of the current user. The course administrator can see the announcement of other users by using the user / group filter
  1127.         $user_id=$_user['user_id'];
  1128.         if (isset($_SESSION['user']))
  1129.         {
  1130.             $user_id=$_SESSION['user'];
  1131.         }
  1132.         if (isset($_SESSION['group']))
  1133.         {
  1134.             $group_id=$_SESSION['group'];
  1135.         }
  1136.  
  1137.         //$group_memberships=GroupManager::get_group_ids($_course['dbName'], $_user['user_id']);
  1138.         $group_memberships=GroupManager::get_group_ids($_course['dbName'],$_user['user_id']);
  1139.  
  1140.         if (api_is_allowed_to_edit() )
  1141.         {
  1142.             // A.1. you are a course admin with a USER filter
  1143.             // => see only the messages of this specific user + the messages of the group (s)he is member of.
  1144.  
  1145.             if (isset($_SESSION['user']))
  1146.             {
  1147.                 if (is_array($group_memberships&& count($group_memberships)>0)
  1148.                 {
  1149.                     $sql="SELECT
  1150.                         announcement.*, toolitemproperties.*
  1151.                         FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1152.                         WHERE announcement.id = toolitemproperties.ref
  1153.                         AND toolitemproperties.tool='announcement'
  1154.                         AND    (toolitemproperties.to_user_id=$user_id OR toolitemproperties.to_group_id IN (0, ".implode(", "$group_memberships).") )
  1155.                         ORDER BY display_order DESC";
  1156.  
  1157.                 }
  1158.                 else
  1159.                 {
  1160.                     $sql="SELECT
  1161.                         announcement.*, toolitemproperties.*
  1162.                         FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1163.                         WHERE announcement.id = toolitemproperties.ref
  1164.                         AND toolitemproperties.tool='announcement'
  1165.                         AND (toolitemproperties.to_user_id=$user_id OR toolitemproperties.to_group_id='0')
  1166.                         AND toolitemproperties.visibility='1'
  1167.                         ORDER BY display_order DESC";
  1168.  
  1169.                 }
  1170.             }
  1171.  
  1172.             // A.2. you are a course admin with a GROUP filter
  1173.             // => see only the messages of this specific group
  1174.             elseif (isset($_SESSION['group']))
  1175.             {
  1176.                 $sql="SELECT
  1177.                     announcement.*, toolitemproperties.*
  1178.                     FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1179.                     WHERE announcement.id = toolitemproperties.ref
  1180.                     AND toolitemproperties.tool='announcement'
  1181.                     AND (toolitemproperties.to_group_id=$group_id OR toolitemproperties.to_group_id='0')
  1182.                     GROUP BY toolitemproperties.ref
  1183.                     ORDER BY display_order DESC";
  1184.             }
  1185.  
  1186.             // A.3 you are a course admin without any group or user filter
  1187.             else
  1188.             {
  1189.                 // A.3.a you are a course admin without user or group filter but WITH studentview
  1190.                 // => see all the messages of all the users and groups without editing possibilities
  1191.  
  1192.                 if (isset($isStudentViewand $isStudentView=="true")
  1193.                 {
  1194.  
  1195.                     $sql="SELECT
  1196.                         announcement.*, toolitemproperties.*
  1197.                         FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1198.                         WHERE announcement.id = toolitemproperties.ref
  1199.                         AND toolitemproperties.tool='announcement'
  1200.                         AND toolitemproperties.visibility='1'
  1201.                         GROUP BY toolitemproperties.ref
  1202.                         ORDER BY display_order DESC";
  1203.                 }
  1204.  
  1205.                 // A.3.a you are a course admin without user or group filter and WTIHOUT studentview (= the normal course admin view)
  1206.                 // => see all the messages of all the users and groups with editing possibilities
  1207.                 else
  1208.                 {
  1209.                     $sql="SELECT
  1210.                         announcement.*, toolitemproperties.*
  1211.                         FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1212.                         WHERE announcement.id = toolitemproperties.ref
  1213.                         AND toolitemproperties.tool='announcement'
  1214.                         AND (toolitemproperties.visibility='0' or toolitemproperties.visibility='1')
  1215.                         GROUP BY toolitemproperties.ref
  1216.                         ORDER BY display_order DESC";
  1217.  
  1218.                 }
  1219.             }
  1220.  
  1221.     }
  1222.     else  //STUDENT
  1223.     {   
  1224.         if (is_array($group_memberships&& count($group_memberships)>0)
  1225.         {
  1226.             
  1227.             $sql="SELECT
  1228.                 announcement.*, toolitemproperties.*
  1229.                 FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1230.                 WHERE announcement.id = toolitemproperties.ref
  1231.                 AND toolitemproperties.tool='announcement'
  1232.                 AND    (toolitemproperties.to_user_id=$user_id OR toolitemproperties.to_group_id IN (0, ".implode(", "$group_memberships).") )
  1233.                 AND toolitemproperties.visibility='1'
  1234.                 ORDER BY display_order DESC";
  1235.  
  1236.         }
  1237.         else
  1238.         {
  1239.             if ($_user['user_id'])
  1240.             {
  1241.                 $sql="SELECT
  1242.                     announcement.*, toolitemproperties.*
  1243.                     FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1244.                     WHERE announcement.id = toolitemproperties.ref
  1245.                     AND toolitemproperties.tool='announcement'
  1246.                     AND (toolitemproperties.to_user_id='".$_user['user_id']."' OR toolitemproperties.to_group_id='0')
  1247.                     AND toolitemproperties.visibility='1'
  1248.                     ORDER BY display_order DESC";
  1249.  
  1250.             }
  1251.             else
  1252.             {
  1253.                 $sql="SELECT
  1254.                     announcement.*, toolitemproperties.*
  1255.                     FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1256.                     WHERE announcement.id = toolitemproperties.ref
  1257.                     AND toolitemproperties.tool='announcement'
  1258.                     AND toolitemproperties.to_group_id='0'
  1259.                     AND toolitemproperties.visibility='1'";
  1260.  
  1261.             }
  1262.         }
  1263.     }
  1264.  
  1265.  
  1266.         $result api_sql_query($sql,__FILE__,__LINE__);
  1267.  
  1268.         $num_rows Database::num_rows($result);
  1269.  
  1270.  
  1271.         /*=================================================
  1272.                        DISPLAY: NO ITEMS
  1273.          =================================================*/
  1274.  
  1275.         if ($num_rows == 0)
  1276.         {
  1277.             echo "<table><tr><td>".get_lang('NoAnnouncements')."</td></tr></table>";
  1278.         }
  1279.  
  1280.         $iterator 1;
  1281.  
  1282.         $bottomAnnouncement $announcement_number;
  1283.  
  1284.  
  1285.         echo "\t\t\t<table width=\"100%\" border=\"1\" cellpadding=\"5\" cellspacing=\"0\"  id=\"agenda_list\">\n";
  1286.  
  1287.         $displayed=array();
  1288.  
  1289.         while ($myrow Database::fetch_array($result))
  1290.         {
  1291.             if (!in_array($myrow['id']$displayed))
  1292.             {
  1293.                 $title         $myrow['title'];
  1294.                 $content     $myrow['content'];
  1295.  
  1296.                 $content     make_clickable($content);
  1297.                 $content     text_filter($content);
  1298.  
  1299.  
  1300.                 /*================================================
  1301.                                        DATE
  1302.                 ================================================*/
  1303.  
  1304.                 $last_post_datetime $myrow['end_date'];
  1305.  
  1306.                 list($last_post_date$last_post_timesplit(" "$last_post_datetime);
  1307.                 list($year$month$dayexplode("-"$last_post_date);
  1308.                 list($hour$minexplode(":"$last_post_time);
  1309.                 $announceDate mktime((int)$hour(int)$min0(int)$month(int)$day(int)$year);
  1310.  
  1311.                 // the styles
  1312.                 if ($myrow['visibility']=='0')
  1313.                 {
  1314.                     $style="data_hidden";
  1315.                     $stylenotbold="datanotbold_hidden";
  1316.                     $text_style="text_hidden";
  1317.                 }
  1318.                 else
  1319.                 {
  1320.                     $style="data";
  1321.                     $stylenotbold="datanotbold";
  1322.                     $text_style="text";
  1323.                 }
  1324.  
  1325.                 echo    "\t\t\t\t<tr class=\"".$style."\">";
  1326.  
  1327.  
  1328.                 /*===================================================================
  1329.                                             THE ICONS
  1330.                 ===================================================================*/
  1331.                 echo "\t\t\t\t\t<td>\n";
  1332.                 // anchoring
  1333.                 echo "<a name=\"".(int)($myrow["id"])."\"></a>\n";
  1334.                 // User or group icon
  1335.                 if ($myrow['to_group_id']!== '0' and $myrow['to_group_id']!== 'NULL')
  1336.                 {
  1337.                     echo "\t\t\t\t\t\t<img alt=\"$alt_ug\" src='../img/group.gif'>\n";
  1338.                 }
  1339.                 // the email icon
  1340.                 if ($myrow['email_sent'== '1')
  1341.                 {
  1342.                     echo "\t\t\t\t\t\t<img alt=\"$alt_mail\" src='../img/email.gif'>\n";
  1343.                 }
  1344.                 echo "\t\t\t\t\t</td>\n";
  1345.                 /*==================================================================
  1346.                                             TITLE
  1347.                 ==================================================================*/
  1348.  
  1349.                 echo "\t\t\t\t\t<td>".$title."</td>\n";
  1350.  
  1351.  
  1352.                 /*==================================================================
  1353.                                             SENT TO
  1354.                 ===================================================================*/
  1355.  
  1356.                 echo "\t\t\t\t\t<td class=\"".$stylenotbold."\">" get_lang("SentTo"" : &nbsp; ";
  1357.                 $sent_to=sent_to("announcement"$myrow['id']);
  1358.  
  1359.                 $sent_to_form=sent_to_form($sent_to);
  1360.                 $user_info=api_get_user_info($myrow['insert_user_id']);
  1361.                 echo '&nbsp;&nbsp;&nbsp;'.get_lang('By').' : &nbsp;'.$user_info['lastName'].'&nbsp;'.$user_info['firstName'];
  1362.                 
  1363.                 echo "\t\t\t\t\t</td>\n","\t\t\t\t</tr>\n";
  1364.  
  1365.  
  1366.                 /*=========================================================
  1367.                                             TITLE
  1368.                 =========================================================*/
  1369.                 echo "\t\t\t\t<tr>\n",
  1370.                 "\t\t\t\t\t<td class=\"announcements_datum\" colspan=\"3\">",
  1371.  
  1372.                 get_lang('AnnouncementPublishedOn')," : ",ucfirst(format_locale_date($dateFormatLong,strtotime($last_post_date))),
  1373.  
  1374.  
  1375.  
  1376.                 "</td>\n",
  1377.                 "\t\t\t\t</tr>\n",
  1378.  
  1379.  
  1380.                 /*=========================================================
  1381.                                         CONTENT
  1382.                 =========================================================*/
  1383.  
  1384.                 "\t\t\t\t<tr class=\"$text_style\">\n",
  1385.                 "\t\t\t\t\t<td colspan=\"3\">\n",
  1386.  
  1387.                 $content,
  1388.  
  1389.                 "\t\t\t\t\t</td>\n",
  1390.                 "\t\t\t\t</tr>\n",
  1391.  
  1392.  
  1393.                 /*========================================================
  1394.                                         RESOURCES
  1395.                 ========================================================*/
  1396.  
  1397.                 "<tr>\n",
  1398.                 "<td colspan=\"3\">\n";
  1399.  
  1400.  
  1401.                 if (check_added_resources("Ad_Valvas"$myrow["id"]))
  1402.                 {
  1403.                     echo "<i>".get_lang('AddedResources')."</i><br />";
  1404.                     display_added_resources("Ad_Valvas"$myrow["id"]);
  1405.                 }
  1406.  
  1407.                 echo   "<br />";
  1408.  
  1409.  
  1410.                 if(api_is_allowed_to_edit(OR (api_get_course_setting('allow_user_edit_announcement'&& !api_is_anonymous()))
  1411.                 {
  1412.                     /*=====================================================================
  1413.                                                 SHOW MOD/DEL/VIS FUNCTIONS
  1414.                     =====================================================================*/
  1415.                     echo "<table><tr>";
  1416.                     echo    "<td valign=\"top\"><a href=\"".api_get_self()."?".api_get_cidreq()."&action=modify&id=".$myrow['id']."\">",
  1417.                             "<img src=\"../img/edit.gif\" title=\"",get_lang('Modify'),"\" border=\"0\" align=\"absmiddle\">",
  1418.                             "</a></td>";
  1419.  
  1420.  
  1421.                     if (api_is_allowed_to_edit()) echo "<td valign=\"top\"><a href=\"".api_get_self()."?".api_get_cidreq()."&action=delete&id=".$myrow['id']."\" onclick=\"javascript:if(!confirm('".addslashes(htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset))."')) return false;\">",
  1422.                             "<img src=\"../img/delete.gif\" title=\"",get_lang('Delete'),"\" border=\"0\" align=\"absmiddle\">",
  1423.                             "</a></td>";
  1424.  
  1425.                             if ($myrow['visibility']==1)
  1426.                             {
  1427.                                     $image_visibility="visible";
  1428.                             }
  1429.                             else
  1430.                             {
  1431.                                     $image_visibility="invisible";
  1432.                             }
  1433.  
  1434.                             echo     "<td valign=\"top\"><a href=\"".api_get_self()."?".api_get_cidreq()."&origin=".(!empty($_GET['origin'])?$_GET['origin']:'')."&action=showhide&id=".$myrow['id']."\">",
  1435.                                     "<img src=\"../img/".$image_visibility.".gif\" border=\"0\" alt=\"".get_lang('Visible')."\"/></a></td>";
  1436.  
  1437.  
  1438.  
  1439.  
  1440.                             // DISPLAY MOVE UP COMMAND only if it is not the top announcement
  1441.                             if($iterator != 1)
  1442.                             {
  1443.  
  1444.                             echo    "<td valign=\"top\"><a href=\"".api_get_self()."?".api_get_cidreq()."&up=",$myrow["id"],"\">",
  1445.                                     "<img src=../img/up.gif border=0 title=\"".get_lang('Up')."\" align=\"absmiddle\">",
  1446.                                     "</a></td>";
  1447.                             }
  1448.  
  1449.  
  1450.                             if($iterator $bottomAnnouncement)
  1451.                             {
  1452.  
  1453.                             echo    "<td valign=\"top\"><a href=\"".api_get_self()."?".api_get_cidreq()."&down=".$myrow["id"]."\">",
  1454.                                     "<img src=\"../img/down.gif\" border=\"0\" title=\"".get_lang('Down')."\" align=\"absmiddle\">",
  1455.                                     "</a></td>";
  1456.                             }
  1457.  
  1458.                             echo "</tr></table>";
  1459.  
  1460.  
  1461.  
  1462.                     echo    "</td>\n",
  1463.                             "</tr>\n";
  1464.  
  1465.                     $iterator ++;
  1466.                 // is_allowed_to_edit
  1467.  
  1468.                 echo "<tr><td width=\"100%\" colspan=\"3\"><a href=\"#top\"><img src=\"../img/top.gif\" border=\"0\" alt=\"To top\" align=\"right\"></a></td></tr>";
  1469.             }
  1470.             $displayed[]=$myrow['id'];
  1471.         }    // end while ($myrow = Database::fetch_array($result))
  1472.  
  1473.         echo "</table>";
  1474.  
  1475. }    // end: if ($displayAnnoucementList)
  1476.  
  1477. echo "</table>";
  1478.  
  1479. if (!empty($display_specific_announcement)) display_announcement($announcement_id);
  1480.  
  1481. /*
  1482. ==============================================================================
  1483.         FOOTER
  1484. ==============================================================================
  1485. */
  1486. if (empty($_GET['origin']or $_GET['origin'!== 'learnpath')
  1487. {
  1488.     //we are not in learnpath tool
  1489. }
  1490. ?>

Documentation generated on Thu, 12 Jun 2008 12:58:25 -0500 by phpDocumentor 1.4.1