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

Source for file announcements.inc.php

Documentation is available at announcements.inc.php

  1. <?php //$Id: announcements.inc.php 15247 2008-05-08 19:07:01Z juliomontoya $
  2. /*
  3. ==============================================================================
  4.     Dokeos - elearning and course management software
  5.  
  6.     Copyright (c) 2004-2008 Dokeos SPRL
  7.     Copyright (c) various contributors
  8.  
  9.     For a full list of contributors, see "credits.txt".
  10.     The full license can be read in "license.txt".
  11.  
  12.     This program is free software; you can redistribute it and/or
  13.     modify it under the terms of the GNU General Public License
  14.     as published by the Free Software Foundation; either version 2
  15.     of the License, or (at your option) any later version.
  16.  
  17.     See the GNU General Public License for more details.
  18.  
  19.     Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  20.     Mail: info@dokeos.com
  21. ==============================================================================
  22. */
  23. /**
  24. ==============================================================================
  25. * Include file with functions for the announcements module.
  26. @package dokeos.announcements
  27. ==============================================================================
  28. */
  29.  
  30. /*
  31. ==============================================================================
  32.         DISPLAY FUNCTIONS
  33. ==============================================================================
  34. */
  35. /**
  36. * displays one specific announcement
  37. @param $announcement_id, the id of the announcement you want to display
  38. @todo remove globals
  39. @todo more security checking
  40. */
  41. function display_announcement($announcement_id)
  42. {
  43.     global $_user$dateFormatLong;
  44.     $tbl_announcement     Database::get_course_table('announcement');
  45.     $tbl_item_property    Database::get_course_table('item_property');
  46.     
  47.     if ($_user['user_id'])
  48.     {
  49.         $sql_query "    SELECT announcement.*, toolitemproperties.*
  50.                         FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  51.                         WHERE announcement.id = toolitemproperties.ref
  52.                         AND announcement.id = '$announcement_id'
  53.                         AND toolitemproperties.tool='announcement'
  54.                         AND (toolitemproperties.to_user_id='".$_user['user_id']."' OR toolitemproperties.to_group_id='0')
  55.                         AND toolitemproperties.visibility='1'
  56.                         ORDER BY display_order DESC";
  57.  
  58.     }
  59.     else
  60.     {
  61.         $sql_query "    SELECT announcement.*, toolitemproperties.*
  62.                         FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  63.                         WHERE announcement.id = toolitemproperties.ref
  64.                         AND announcement.id = '$announcement_id'
  65.                         AND toolitemproperties.tool='announcement'
  66.                         AND toolitemproperties.to_group_id='0'
  67.                         AND toolitemproperties.visibility='1'";
  68.     }
  69.     $sql_result api_sql_query($sql_query,__FILE__,__LINE__);
  70.     $result Database::fetch_array($sql_result);
  71.     
  72.     $title         $result['title'];
  73.     $content     $result['content'];
  74.     $content     make_clickable($content);
  75.     $content     text_filter($content);
  76.     $last_post_datetime $result['insert_date'];// post time format  datetime de mysql
  77.     list($last_post_date$last_post_timesplit(" "$last_post_datetime);
  78.     
  79.     echo "<table height=\"100\" width=\"100%\" border=\"1\" cellpadding=\"5\" cellspacing=\"0\" id=\"agenda_list\">\n";
  80.     echo "<tr class=\"data\"><td>" $title "</td></tr>\n";
  81.     echo "<tr><td class=\"announcements_datum\">" get_lang('AnnouncementPublishedOn'" : " ucfirst(format_locale_date($dateFormatLong,strtotime($last_post_date) ) ) "</td></tr>\n";
  82.     echo "<tr class=\"text\"><td>$content</td></tr>\n";
  83.     echo "</table>";
  84. }
  85.  
  86. /*======================================
  87.               SHOW_TO_FORM
  88. ======================================*/
  89. /**
  90. * this function shows the form for sending a message to a specific group or user.
  91. */
  92. function show_to_form($to_already_selected)
  93. {
  94.     $user_list=get_course_users();
  95.     $group_list=get_course_groups();
  96.  
  97.     echo "\n<table id=\"recipient_list\" style=\"display: none;\">\n";
  98.     echo "\t<tr>\n";
  99.     
  100.     // the form containing all the groups and all the users of the course
  101.     echo "\t\t<td>\n";
  102.     construct_not_selected_select_form($group_list,$user_list,$to_already_selected);
  103.     echo "\t\t</td>\n";
  104.     
  105.     // the buttons for adding or removing groups/users
  106.     echo "\n\t\t<td valign=\"middle\">\n";
  107.     echo "\t\t<input    type=\"button\"    ",
  108.                 "onClick=\"move(this.form.elements[0],this.form.elements[3])\" ",// 7 & 4 : fonts
  109.                 "value=\"   >>   \">",
  110.  
  111.                 "\n\t\t<p>&nbsp;</p>",
  112.  
  113.                 "\n\t\t<input    type=\"button\"",
  114.                 "onClick=\"move(this.form.elements[3],this.form.elements[0])\" ",
  115.                 "value=\"   <<   \">";
  116.     echo "\t\t</td>\n";
  117.     echo "\n\t\t<td>\n";
  118.     
  119.     // the form containing the selected groups and users
  120.     construct_selected_select_form($group_list,$user_list,$to_already_selected);
  121.     echo "\t\t</td>\n";
  122.     echo "\t</tr>\n";
  123.     echo "</table>";
  124. }
  125.  
  126.  
  127. /*===========================================
  128.       CONSTRUCT_NOT_SELECT_SELECT_FORM
  129. ===========================================*/
  130. /**
  131. * this function shows the form for sending a message to a specific group or user.
  132. */
  133. function construct_not_selected_select_form($group_list=null$user_list=null,$to_already_selected)
  134. {
  135.  
  136.     echo "\t\t<select name=\"not_selected_form[]\" size=5 style=\"width:200px\" multiple>\n";
  137.     // adding the groups to the select form
  138.     if ($group_list)
  139.     {
  140.         foreach($group_list as $this_group)
  141.         {
  142.             if (is_array($to_already_selected))
  143.             {
  144.                 if (!in_array("GROUP:".$this_group['id'],$to_already_selected)) // $to_already_selected is the array containing the groups (and users) that are already selected
  145.                 {
  146.                     echo    "\t\t<option value=\"GROUP:".$this_group['id']."\">",
  147.                     "G: ",$this_group['name']," - " $this_group['userNb'" " get_lang('Users'.
  148.                     "</option>\n";
  149.                 }
  150.             }
  151.         }
  152.         // a divider
  153.         echo    "\t\t<option value=\"\">---------------------------------------------------------</option>\n";
  154.     }
  155.     // adding the individual users to the select form
  156.     foreach($user_list as $this_user)
  157.     {
  158.         if (!in_array("USER:".$this_user["user_id"],$to_already_selected)) // $to_already_selected is the array containing the users (and groups) that are already selected
  159.         {
  160.             echo    "\t\t<option value=\"USER:",$this_user["user_id"],"\">",
  161.                 "",$this_user['lastName']," ",$this_user['firstName'],
  162.                 "</option>\n";
  163.         }
  164.     }
  165.     echo "\t\t</select>\n";
  166. }
  167.  
  168.  
  169.  
  170. /*==========================================
  171.        CONSTRUCT_SELECTED_SELECT_FORM
  172. ==========================================*/
  173. /**
  174. * this function shows the form for sending a message to a specific group or user.
  175. */
  176. function construct_selected_select_form($group_list=null$user_list=null,$to_already_selected)
  177. {
  178.     // we separate the $to_already_selected array (containing groups AND users into
  179.     // two separate arrays
  180.     $groupuser array();
  181.     if (is_array($to_already_selected))
  182.     {
  183.         $groupuser=separate_users_groups($to_already_selected);
  184.     }
  185.     $groups_to_already_selected=$groupuser['groups'];
  186.     $users_to_already_selected=$groupuser['users'];
  187.  
  188.     // we load all the groups and all the users into a reference array that we use to search the name of the group / user
  189.     $ref_array_groups=get_course_groups();
  190.     $ref_array_users=get_course_users();
  191.  
  192.     // we construct the form of the already selected groups / users
  193.     echo "\t\t<select name=\"selectedform[]\" size=\"5\" multiple style=\"width:200px\" width=\"200px\">";
  194.     foreach($to_already_selected as $groupuser)
  195.     {
  196.         list($type,$id)=explode(":",$groupuser);
  197.         if ($type=="GROUP")
  198.         {
  199.             echo "\t\t<option value=\"".$groupuser."\">G: ".$ref_array_groups[$id]['name']."</option>";
  200.         }
  201.         else
  202.         {
  203.             
  204.             foreach($ref_array_users as $key=>$value){
  205.  
  206.                 if($value['user_id']==$id){
  207.                     echo "\t\t<option value=\"".$groupuser."\">".$value['lastName']." ".$value['firstName']."</option>";
  208.                     break;
  209.                 }
  210.                 
  211.             }
  212.         }
  213.     }
  214.     echo "</select>\n";
  215. }
  216.  
  217.  
  218. /**
  219. * this function shows the form for sending a message to a specific group or user.
  220. */
  221. function show_to_form_group($group_id)
  222. {
  223.  
  224.     echo "\n<table id=\"recipient_list\" style=\"display: none;\">\n";
  225.     echo "\t<tr>\n";
  226.  
  227.     echo "\t\t<td>\n";
  228.     
  229.     echo "\t\t<select name=\"not_selected_form[]\" size=5 style=\"width:200px\" multiple>\n";
  230.     $group_users GroupManager::get_subscribed_users($group_id);
  231.     foreach($group_users as $user){
  232.         echo '<option value="'.$user['user_id'].'">'.$user['lastname'].' '.$user['firstname'].'</option>';
  233.     }
  234.     echo '</select>';
  235.     
  236.     echo "\t\t</td>\n";
  237.     
  238.     // the buttons for adding or removing groups/users
  239.     echo "\n\t\t<td valign=\"middle\">\n";
  240.     echo "\t\t<input    type=\"button\"    ",
  241.                 "onClick=\"move(this.form.elements[1],this.form.elements[4])\" ",// 7 & 4 : fonts
  242.                 "value=\"   >>   \">",
  243.  
  244.                 "\n\t\t<p>&nbsp;</p>",
  245.  
  246.                 "\n\t\t<input    type=\"button\"",
  247.                 "onClick=\"move(this.form.elements[4],this.form.elements[1])\" ",
  248.                 "value=\"   <<   \">";
  249.     echo "\t\t</td>\n";
  250.     echo "\n\t\t<td>\n";
  251.     
  252.     echo "\t\t<select name=\"selectedform[]\" size=5 style=\"width:200px\" multiple>\n";
  253.     echo '</select>';
  254.     
  255.     echo "\t\t</td>\n";
  256.     echo "\t</tr>\n";
  257.     echo "</table>";
  258. }
  259.  
  260.  
  261. /*
  262. ==============================================================================
  263.         DATA FUNCTIONS
  264. ==============================================================================
  265. */
  266.  
  267. /**
  268. * this function gets all the users of the course,
  269. * including users from linked courses
  270. */
  271. function get_course_users()
  272. {
  273.     //this would return only the users from real courses:
  274.     //$user_list = CourseManager::get_user_list_from_course_code(api_get_course_id());
  275.     
  276.     $user_list CourseManager::get_real_and_linked_user_list(api_get_course_id()true$_SESSION['id_session']);
  277.     return $user_list;
  278. }
  279.  
  280. /**
  281. * this function gets all the groups of the course,
  282. * not including linked courses
  283. */
  284. function get_course_groups()
  285. {
  286.     return $new_group_list;
  287. }
  288.  
  289. /*======================================
  290.               LOAD_EDIT_USERS
  291. ======================================*/
  292. /**
  293. * This tools loads all the users and all the groups who have received
  294. * a specific item (in this case an announcement item)
  295. */
  296. function load_edit_users($tool$id)
  297. {
  298.     global $_course;
  299.     global $tbl_item_property;
  300.  
  301.     $sql="SELECT * FROM $tbl_item_property WHERE tool='$tool' AND ref='$id'";
  302.     $result=api_sql_query($sql,__FILE__,__LINE__or die (mysql_error());
  303.     while ($row=Database::fetch_array($result))
  304.     {
  305.         $to_group=$row['to_group_id'];
  306.         switch ($to_group)
  307.         {
  308.             // it was send to one specific user
  309.             case null:
  310.                 $to[]="USER:".$row['to_user_id'];
  311.                 break;
  312.             // it was sent to everyone
  313.             case 0:
  314.                  return "everyone";
  315.                  exit;
  316.                  break;
  317.             default:
  318.                 $to[]="GROUP:".$row['to_group_id'];
  319.         }
  320.     }
  321.     return $to;
  322. }
  323.  
  324.  
  325.  
  326. /*======================================
  327.      USER_GROUP_FILTER_JAVASCRIPT
  328. ======================================*/
  329. /**
  330. * returns the javascript for setting a filter
  331. * this goes into the $htmlHeadXtra[] array
  332. */
  333. {
  334.     return "<script language=\"JavaScript\" type=\"text/JavaScript\">
  335.     <!--
  336.     function jumpMenu(targ,selObj,restore)
  337.     {
  338.       eval(targ+\".location='\"+selObj.options[selObj.selectedIndex].value+\"'\");
  339.       if (restore) selObj.selectedIndex=0;
  340.     }
  341.     //-->
  342.     </script>
  343.     ";
  344. }
  345.  
  346.  
  347. /*======================================
  348.              TO_JAVASCRIPT
  349. ========================================*/
  350. /**
  351. * returns all the javascript that is required for easily
  352. * setting the target people/groups
  353. * this goes into the $htmlHeadXtra[] array
  354. */
  355. function to_javascript()
  356. {
  357.     return "<script type=\"text/javascript\" language=\"JavaScript\">
  358.  
  359.     <!-- Begin javascript menu swapper
  360.  
  361.     function move(fbox,    tbox)
  362.     {
  363.         var    arrFbox    = new Array();
  364.         var    arrTbox    = new Array();
  365.         var    arrLookup =    new    Array();
  366.  
  367.         var    i;
  368.         for    (i = 0;    i <    tbox.options.length; i++)
  369.         {
  370.             arrLookup[tbox.options[i].text]    = tbox.options[i].value;
  371.             arrTbox[i] = tbox.options[i].text;
  372.         }
  373.  
  374.         var    fLength    = 0;
  375.         var    tLength    = arrTbox.length;
  376.  
  377.         for(i =    0; i < fbox.options.length;    i++)
  378.         {
  379.             arrLookup[fbox.options[i].text]    = fbox.options[i].value;
  380.  
  381.             if (fbox.options[i].selected &&    fbox.options[i].value != \"\")
  382.             {
  383.                 arrTbox[tLength] = fbox.options[i].text;
  384.                 tLength++;
  385.             }
  386.             else
  387.             {
  388.                 arrFbox[fLength] = fbox.options[i].text;
  389.                 fLength++;
  390.             }
  391.         }
  392.  
  393.         arrFbox.sort();
  394.         arrTbox.sort();
  395.         fbox.length    = 0;
  396.         tbox.length    = 0;
  397.  
  398.         var    c;
  399.         for(c =    0; c < arrFbox.length; c++)
  400.         {
  401.             var    no = new Option();
  402.             no.value = arrLookup[arrFbox[c]];
  403.             no.text    = arrFbox[c];
  404.             fbox[c]    = no;
  405.         }
  406.         for(c =    0; c < arrTbox.length; c++)
  407.         {
  408.             var    no = new Option();
  409.             no.value = arrLookup[arrTbox[c]];
  410.             no.text    = arrTbox[c];
  411.             tbox[c]    = no;
  412.         }
  413.     }
  414.  
  415.     function validate()
  416.     {
  417.         var    f =    document.new_calendar_item;
  418.         f.submit();
  419.         return true;
  420.     }
  421.  
  422.  
  423.     function selectAll(cbList,bSelect,showwarning)
  424.     {
  425.         if (cbList.length <    1) {
  426.             alert(\"".get_lang('Send2All')."\");
  427.             return;
  428.         }
  429.         for    (var i=0; i<cbList.length; i++)
  430.             cbList[i].selected = cbList[i].checked = bSelect
  431.     }
  432.  
  433.     function reverseAll(cbList)
  434.     {
  435.         for    (var i=0; i<cbList.length; i++)
  436.         {
  437.             cbList[i].checked  = !(cbList[i].checked)
  438.             cbList[i].selected = !(cbList[i].selected)
  439.         }
  440.     }
  441.     //    End    -->
  442.     </script>";
  443. }
  444.  
  445.  
  446. /*======================================
  447.             SENT_TO_FORM
  448. ======================================*/
  449. /**
  450. * constructs the form to display all the groups and users the message has been sent to
  451. * input:     $sent_to_array is a 2 dimensional array containing the groups and the users
  452. *            the first level is a distinction between groups and users:
  453. *            $sent_to_array['groups'] * and $sent_to_array['users']
  454. *            $sent_to_array['groups'] (resp. $sent_to_array['users']) is also an array
  455. *            containing all the id's of the groups (resp. users) who have received this message.
  456. @author Patrick Cool <patrick.cool@>
  457. */
  458. function sent_to_form($sent_to_array)
  459. {
  460.     // we find all the names of the groups
  461.     $group_names=get_course_groups();
  462.  
  463.     count($sent_to_array);
  464.  
  465.     // we count the number of users and the number of groups
  466.     if (isset($sent_to_array['users']))
  467.     {
  468.         $number_users=count($sent_to_array['users']);
  469.     }
  470.     else
  471.     {
  472.         $number_users=0;
  473.     }
  474.     if (isset($sent_to_array['groups']))
  475.     {
  476.         $number_groups=count($sent_to_array['groups']);
  477.     }
  478.     else
  479.     {
  480.             $number_groups=0;
  481.     }
  482.     $total_numbers=$number_users+$number_groups;
  483.  
  484.     // starting the form if there is more than one user/group
  485.     if ($total_numbers >1)
  486.     {
  487.         $output="<select name=\"sent to\">\n";
  488.         $output.="<option>".get_lang("SentTo")."</option>";
  489.         // outputting the name of the groups
  490.         if (is_array($sent_to_array['groups']))
  491.         {
  492.             foreach ($sent_to_array['groups'as $group_id)
  493.             {
  494.                 $output.="\t<option value=\"\">G: ".$group_names[$group_id]['name']."</option>\n";
  495.             }
  496.         }
  497.         
  498.         if (isset($sent_to_array['users']))
  499.         {
  500.             if (is_array($sent_to_array['users']))
  501.             {
  502.                 foreach ($sent_to_array['users'as $user_id)
  503.                 {
  504.                     $user_info=api_get_user_info($user_id);
  505.                     $output.="\t<option value=\"\">".$user_info['lastName']." ".$user_info['firstName']."</option>\n";
  506.                 }
  507.             }
  508.         }
  509.         
  510.         // ending the form
  511.         $output.="</select>\n";
  512.     }
  513.     else // there is only one user/group
  514.     {
  515.         if (isset($sent_to_array['users']and is_array($sent_to_array['users']))
  516.         {
  517.             $user_info=api_get_user_info($sent_to_array['users'][0]);
  518.             echo $user_info['lastName']." ".$user_info['firstName'];
  519.         }
  520.         if (isset($sent_to_array['groups']and is_array($sent_to_array['groups']and $sent_to_array['groups'][0]!==0)
  521.         {
  522.             $group_id=$sent_to_array['groups'][0];
  523.             echo $group_names[$group_id]['name'];
  524.         }
  525.         if (isset($sent_to_array['groups']and is_array($sent_to_array['groups']and $sent_to_array['groups'][0]==0)
  526.         {
  527.             echo get_lang("Everybody");
  528.         }
  529.     }
  530.     if(!empty($output))
  531.     {
  532.         echo $output;
  533.     }
  534. }
  535.  
  536.  
  537. /*======================================
  538.             SEPARATE_USERS_GROUPS
  539.     ======================================*/
  540. /**
  541. * This function separates the users from the groups
  542. * users have a value USER:XXX (with XXX the dokeos id
  543. * groups have a value GROUP:YYY (with YYY the group id)
  544. */
  545. function separate_users_groups($to)
  546. {
  547.     foreach($to as $to_item)
  548.     {
  549.         list($type$idexplode(':'$to_item);
  550.  
  551.         switch($type)
  552.         {
  553.             case 'GROUP':
  554.                 $grouplist[=$id;
  555.                 break;
  556.             case 'USER':
  557.                 $userlist[=$id;
  558.                 break;
  559.         }
  560.     }
  561.  
  562.     $send_to['groups']=$grouplist;
  563.     $send_to['users']=$userlist;
  564.     return $send_to;
  565. }
  566.  
  567.  
  568.  
  569. /*======================================
  570.                  SENT_TO()
  571.   ======================================*/
  572. /**
  573. * returns all the users and all the groups a specific announcement item
  574. * has been sent to
  575. */
  576. function sent_to($tool$id)
  577. {
  578.     global $_course;
  579.     global $tbl_item_property;
  580.  
  581.     $sql="SELECT * FROM $tbl_item_property WHERE tool='$tool' AND ref='".$id."'";
  582.     $result api_sql_query($sql,__FILE__,__LINE__);
  583.  
  584.     while ($row=Database::fetch_array($result))
  585.     {
  586.         // if to_group_id is null then it is sent to a specific user
  587.         // if to_group_id = 0 then it is sent to everybody
  588.         if (!is_null($row['to_group_id']))
  589.         {
  590.             $sent_to_group[]=$row['to_group_id'];
  591.         }
  592.         // if to_user_id <> 0 then it is sent to a specific user
  593.         if ($row['to_user_id'<> 0)
  594.         {
  595.             $sent_to_user[]=$row['to_user_id'];
  596.         }
  597.     }
  598.     if (isset($sent_to_group))
  599.     {
  600.         $sent_to['groups']=$sent_to_group;
  601.     }
  602.     if (isset($sent_to_user))
  603.     {
  604.         $sent_to['users']=$sent_to_user;
  605.     }
  606.     return $sent_to;
  607. }
  608.  
  609.  
  610. /*===================================================
  611.                CHANGE_VISIBILITY($tool,$id)
  612.   =================================================*/
  613. /**
  614. * This functions swithes the visibility a course resource
  615. * using the visibility field in 'item_property'
  616. * values: 0 = invisibility for
  617. */
  618. function change_visibility($tool,$id)
  619. {
  620.     global $_course;
  621.     global $tbl_item_property;
  622.  
  623.     $sql="SELECT * FROM $tbl_item_property WHERE tool='$tool' AND ref='$id'";
  624.  
  625.     $result=api_sql_query($sql,__FILE__,__LINE__or die (mysql_error());
  626.     $row=Database::fetch_array($result);
  627.  
  628.     if ($row['visibility']=='1')
  629.     {
  630.         $sql_visibility="UPDATE $tbl_item_property SET visibility='0' WHERE tool='$tool' AND ref='$id'";
  631.     }
  632.     else
  633.     {
  634.         $sql_visibility="UPDATE $tbl_item_property SET visibility='1' WHERE tool='$tool' AND ref='$id'";
  635.     }
  636.  
  637.     $result=api_sql_query($sql_visibility,__FILE__,__LINE__or die (mysql_error());
  638. }
  639.  
  640.  
  641. /*====================================================
  642.                 STORE_ADVALVAS_ITEM
  643. ====================================================*/
  644.  
  645. function store_advalvas_item($emailTitle,$newContent$order$to)
  646. {
  647.  
  648.     global $_course;
  649.     global $nameTools;
  650.     global $_user;
  651.  
  652.     global $tbl_announcement;
  653.     global $tbl_item_property;
  654.  
  655.     // store in the table announcement
  656.     $sql "INSERT INTO $tbl_announcement SET content = '$newContent', title = '$emailTitle', end_date = NOW(), display_order ='$order'";
  657.     $result api_sql_query($sql,__FILE__,__LINE__or die (mysql_error());
  658.     $last_idDatabase::get_last_insert_id();
  659.  
  660.     // store in item_property (first the groups, then the users
  661.     if (!is_null($to)) // !is_null($to): when no user is selected we send it to everyone
  662.     {
  663.         $send_to=separate_users_groups($to);
  664.         // storing the selected groups
  665.         if (is_array($send_to['groups']))
  666.         {
  667.             foreach ($send_to['groups'as $group)
  668.             {
  669.                 api_item_property_update($_courseTOOL_ANNOUNCEMENT$last_id"AnnouncementAdded"$_user['user_id']$group)
  670.             }
  671.         }
  672.  
  673.         // storing the selected users
  674.         if (is_array($send_to['users']))
  675.         {
  676.             foreach ($send_to['users'as $user)
  677.             {
  678.                     api_item_property_update($_courseTOOL_ANNOUNCEMENT$last_id"AnnouncementAdded"$_user['user_id']''$user);
  679.             }
  680.         }
  681.     }
  682.     else // the message is sent to everyone, so we set the group to 0
  683.     {
  684.         api_item_property_update($_courseTOOL_ANNOUNCEMENT$last_id"AnnouncementAdded"$_user['user_id']'0');
  685.     }
  686.  
  687.     return $last_id;
  688.  
  689. }
  690.  
  691.  
  692. function store_advalvas_group_item($emailTitle,$newContent$order$to$to_users)
  693. {
  694.     
  695.     global $_course;
  696.     global $nameTools;
  697.     global $_user;
  698.  
  699.     global $tbl_announcement;
  700.     global $tbl_item_property;
  701.  
  702.     // store in the table announcement
  703.     $sql "INSERT INTO $tbl_announcement SET content = '$newContent', title = '$emailTitle', end_date = NOW(), display_order ='$order'";
  704.     $result api_sql_query($sql,__FILE__,__LINE__or die (mysql_error());
  705.     $last_idDatabase::get_last_insert_id();
  706.  
  707.     // store in item_property (first the groups, then the users
  708.     if (!isset($to_users)) // !isset($to): when no user is selected we send it to everyone
  709.     {
  710.         $send_to=separate_users_groups($to);
  711.         // storing the selected groups
  712.         if (is_array($send_to['groups']))
  713.         {
  714.             foreach ($send_to['groups'as $group)
  715.             {
  716.                 api_item_property_update($_courseTOOL_ANNOUNCEMENT$last_id"AnnouncementAdded"$_user['user_id']$group)
  717.             }
  718.         }
  719.     }
  720.     else // the message is sent to everyone, so we set the group to 0
  721.     {
  722.         // storing the selected users
  723.         if (is_array($to_users))
  724.         {
  725.             foreach ($to_users as $user)
  726.             {
  727.                 api_item_property_update($_courseTOOL_ANNOUNCEMENT$last_id"AnnouncementAdded"$_user['user_id']''$user);
  728.             }
  729.         }
  730.     }
  731.  
  732.     return $last_id;
  733.  
  734. }
  735.  
  736.  
  737. /*==================================================
  738.                EDIT_VALVAS_ITEM
  739. ==================================================*/
  740. /**
  741. * This function stores the announcement Item in the table announcement
  742. * and updates the item_property also
  743. */
  744. function edit_advalvas_item($id,$emailTitle,$newContent,$to)
  745. {
  746.     global $_course;
  747.     global $nameTools;
  748.     global $_user;
  749.  
  750.     global $tbl_announcement;
  751.     global $tbl_item_property;
  752.     
  753.     // store the modifications in the table announcement
  754.     $sql "UPDATE $tbl_announcement SET content='$newContent', title = '$emailTitle' WHERE id='$id'";
  755.  
  756.     $result api_sql_query($sql,__FILE__,__LINE__or die (mysql_error());
  757.  
  758.     // we remove everything from item_property for this
  759.     $sql_delete="DELETE FROM $tbl_item_property WHERE ref='$id' AND tool='announcement'";
  760.     $result api_sql_query($sql_delete,__FILE__,__LINE__or die (mysql_error());
  761.  
  762.     // store in item_property (first the groups, then the users
  763.     if (!is_null($to)) // !is_null($to): when no user is selected we send it to everyone
  764.     {
  765.         $send_to=separate_users_groups($to);
  766.         // storing the selected groups
  767.         if (is_array($send_to['groups']))
  768.         {
  769.             foreach ($send_to['groups'as $group)
  770.             {
  771.                 api_item_property_update($_courseTOOL_ANNOUNCEMENT$id"AnnouncementUpdated"$_user['user_id']$group);
  772.             }
  773.         }
  774.         // storing the selected users
  775.         if (is_array($send_to['users']))
  776.         {
  777.             foreach ($send_to['users'as $user)
  778.             {
  779.                     api_item_property_update($_courseTOOL_ANNOUNCEMENT$id"AnnouncementUpdated"$_user['user_id']''$user);
  780.             }
  781.         }
  782.     }
  783.     else // the message is sent to everyone, so we set the group to 0
  784.     {
  785.         api_item_property_update($_courseTOOL_ANNOUNCEMENT$id"AnnouncementUpdated"$_user['user_id']'0');
  786.     }
  787. }
  788.  
  789.  
  790. /*
  791. ==============================================================================
  792.         MAIL FUNCTIONS
  793. ==============================================================================
  794. */
  795.  
  796. /**
  797. * Sends an announcement by email to a list of users.
  798. * Emails are sent one by one to try to avoid antispam.
  799. */
  800. function send_announcement_email($user_list$course_code$_course$mail_title$mail_content)
  801. {
  802.     global $_user;
  803.     foreach ($user_list as $this_user)
  804.     {
  805.         /*    Header : Bericht van uw lesgever - GES ($course_code) - Morgen geen les! ($mail_title)
  806.                 Body :   John Doe (prenom + nom) <john_doe@hotmail.com> (email)
  807.  
  808.                         Morgen geen les! ($mail_title)
  809.  
  810.                         Morgen is er geen les, de les wordt geschrapt wegens vergadering (newContent)
  811.         */
  812.         $mail_subject get_lang('professorMessage').' - '.$_course['official_code'].' - '.$mail_title;
  813.  
  814.         $mail_body '['.$_course['official_code'].'] - ['.$_course['name']."]\n";
  815.         $mail_body .= $this_user['lastname'].' '.$this_user['firstname'].' <'.$this_user["email"]."> \n\n".stripslashes($mail_title)."\n\n".trim(stripslashes(html_entity_decode(strip_tags(str_replace(array('<p>','</p>','<br />'),array('',"\n","\n"),$mail_content)))))." \n\n-- \n";
  816.         $mail_body .= $_user['firstName'].' '.$_user['lastName'].' ';
  817.         $mail_body .= '<'.$_user['mail'].">\n";
  818.         $mail_body .= $_course['official_code'].' '.$_course['name'];
  819.         
  820.         //set the charset and use it for the encoding of the email - small fix, not really clean (should check the content encoding origin first)
  821.         //here we use the encoding used for the webpage where the text is encoded (ISO-8859-1 in this case)
  822.         if(empty($charset)){$charset='ISO-8859-1';}
  823.         $encoding 'Content-Type: text/plain; charset='$charset;
  824.         
  825.         $newmail api_mail($this_user['lastname'].' '.$this_user['firstname']$this_user['email']$mail_subject$mail_body$_SESSION['_user']['lastName'].' '.$_SESSION['_user']['firstName']$_SESSION['_user']['mail']$encoding);
  826.     }
  827. }
  828.  
  829. function update_mail_sent($insert_id)
  830. {
  831.     global $_course;
  832.     global $tbl_announcement;
  833.  
  834.     // store the modifications in the table tbl_annoucement
  835.     $sql "UPDATE $tbl_announcement SET email_sent='1' WHERE id='$insert_id'";
  836.     api_sql_query($sql,__FILE__,__LINE__);
  837. }

Documentation generated on Thu, 12 Jun 2008 12:57:43 -0500 by phpDocumentor 1.4.1