Yannick Warnier 14 éve
szülő
commit
749d6acb3f

+ 29 - 37
main/admin/user_fields_add.php

@@ -84,17 +84,16 @@ function change_image_user_field (image_value) {
 	}
 }
 
-	function advanced_parameters() {
-			
-			if(document.getElementById(\'options\').style.display == \'none\') {
-				document.getElementById(\'options\').style.display = \'block\';
-				document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;<img style="vertical-align:middle;" src="../img/div_hide.gif" alt="" />&nbsp;'.get_lang('AdvancedParameters').'\';
+function advanced_parameters() {			
+	if(document.getElementById(\'options\').style.display == \'none\') {
+		document.getElementById(\'options\').style.display = \'block\';
+		document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;<img style="vertical-align:middle;" src="../img/div_hide.gif" alt="" />&nbsp;'.get_lang('AdvancedParameters').'\';
 
-			} else {
-					document.getElementById(\'options\').style.display = \'none\';
-					document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;<img style="vertical-align:middle;" src="../img/div_show.gif" alt="" />&nbsp;'.get_lang('AdvancedParameters').'\';
-				}
-		}
+	} else {
+		document.getElementById(\'options\').style.display = \'none\';
+		document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;<img style="vertical-align:middle;" src="../img/div_show.gif" alt="" />&nbsp;'.get_lang('AdvancedParameters').'\';
+	}
+}
 
 </script>';
 // Database table definitions
@@ -161,15 +160,14 @@ $form->addElement('hidden','fieldid',Security::remove_XSS($_GET['field_id']));
 $form->addElement('text','fieldlabel',get_lang('FieldLabel'));
 $form->applyFilter('fieldlabel','html_filter');
 $form->addRule('fieldlabel', get_lang('OnlyLettersAndNumbersAllowed'), 'username');
-$form->addRule('fieldlabel', '', 'maxlength',20);
+$form->addRule('fieldlabel', '', 'maxlength',60);
 //$form->addRule('fieldlabel', get_lang('FieldTaken'), 'fieldlabel_available');
 
 // Field options possible
 $form->addElement('text','fieldoptions',get_lang('FieldPossibleValues').Display::return_icon('info3.gif', get_lang('FieldPossibleValuesComment'), array('align' => 'absmiddle', 'hspace' => '3px')));
 $form->applyFilter('fieldoptions','trim');
 
-if (is_numeric($_GET['field_id']))
-{
+if (is_numeric($_GET['field_id'])) {
 	$form->addElement('static', 'option_reorder', '', '<a href="user_fields_options.php?field_id='.Security::remove_XSS($_GET['field_id']).'">'.get_lang('ReorderOptions').'</a>');
 }
 
@@ -179,8 +177,7 @@ $form->applyFilter('fielddefaultvalue','trim');
 
 // Set default values (only not empty when editing)
 $defaults = array();
-if (is_numeric($_GET['field_id']))
-{
+if (is_numeric($_GET['field_id'])) {
 	$form_information = UserManager::get_extra_field_information((int)$_GET['field_id']);
 	$defaults['fieldtitle'] = $form_information['field_display_text'];
 	$defaults['fieldlabel'] = $form_information['field_variable'];
@@ -190,14 +187,10 @@ if (is_numeric($_GET['field_id']))
 	$count = 0;
 	// we have to concatenate the options
 	if (count($form_information['options'])>0) {
-		foreach ($form_information['options'] as $option_id=>$option)
-		{
-			if ($count<>0)
-			{
+		foreach ($form_information['options'] as $option_id=>$option) {
+			if ($count<>0) {
 				$defaults['fieldoptions'] = $defaults['fieldoptions'].'; '.$option['option_display_text'];
-			}
-			else
-			{
+			} else {
 				$defaults['fieldoptions'] = $option['option_display_text'];
 			}
 			$count++;
@@ -206,21 +199,21 @@ if (is_numeric($_GET['field_id']))
 }
 
 $form->setDefaults($defaults);
-	if(isset($_GET['field_id']) && !empty($_GET['field_id'])) {
-		$class="save";
-		$text=get_lang('buttonEditUserField');
-	} else { 
-		$class="add";
-		$text=get_lang('buttonAddUserField');
-	}
-	
-$form -> addElement('html','</div>');
+
+if(isset($_GET['field_id']) && !empty($_GET['field_id'])) {
+	$class="save";
+	$text=get_lang('buttonEditUserField');
+} else { 
+	$class="add";
+	$text=get_lang('buttonAddUserField');
+}
+$form->addElement('html','</div>');
+
 // Submit button
 $form->addElement('style_submit_button', 'submit',$text, 'class='.$class.'');
 // Validate form
-if( $form->validate())
-{
-	$check = Security::check_token('post');
+if( $form->validate()) {
+	$check = Security::check_token('post'); 
 	if($check) {
 		$field = $form->exportValues();
 		$fieldlabel = empty($field['fieldlabel'])?$field['fieldtitle']:$field['fieldlabel'];		
@@ -244,7 +237,7 @@ if( $form->validate())
 		header('Location: user_fields.php?action=show_message&message='.urlencode(get_lang('FieldAdded')));
 		exit ();
 	}
-}else{
+} else {
 	if(isset($_POST['submit'])){
 		Security::clear_token();
 	}
@@ -294,5 +287,4 @@ if(!empty($defaults['fieldtype'])) {
 echo '</div>';
 
 // footer
-Display::display_footer();
-?>
+Display::display_footer();

+ 8 - 18
main/auth/profile.php

@@ -97,16 +97,12 @@ EOF;
 }
 
 /*
------------------------------------------------------------
 	Configuration file
------------------------------------------------------------
 */
 require_once api_get_path(CONFIGURATION_PATH).'profile.conf.php';
 
 /*
------------------------------------------------------------
 	Libraries
------------------------------------------------------------
 */
 require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
 require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
@@ -115,13 +111,10 @@ require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
 require_once api_get_path(LIBRARY_PATH).'social.lib.php';
 
 $tool_name = is_profile_editable() ? get_lang('ModifProfile') : get_lang('ViewProfile');
-
 $table_user = Database :: get_main_table(TABLE_MAIN_USER);
 
 /*
------------------------------------------------------------
 	Form
------------------------------------------------------------
 */
 
 /*
@@ -329,15 +322,21 @@ foreach ($extra as $id => $field_details) {
 			if ($field_details[7] == 0)	$form->freeze('extra_'.$field_details[1]);
 			break;
 		case USER_FIELD_TYPE_SELECT:
-			$options = array();
+		    if (in_array($field_details[1], array('mail_notify_invitation', 'mail_notify_message', 'mail_notify_group_message'))) {
+		        $field_details[3] = get_lang($field_details[3]);
+		    }
+			$options = array();			
 			foreach ($field_details[9] as $option_id => $option_details) {
+			    if (in_array($field_details[1], array('mail_notify_invitation', 'mail_notify_message', 'mail_notify_group_message'))) {
+			        $option_details[2] = get_lang($option_details[2]);
+			    }
 				$options[$option_details[1]] = $option_details[2];
 			}
 			$form->addElement('select', 'extra_'.$field_details[1], $field_details[3], $options, '');
 			if ($field_details[7] == 0)	$form->freeze('extra_'.$field_details[1]);
 			break;
 		case USER_FIELD_TYPE_SELECT_MULTIPLE:
-			$options = array();
+			$options = array();			
 			foreach ($field_details[9] as $option_id => $option_details) {
 				$options[$option_details[1]] = $option_details[2];
 			}
@@ -476,16 +475,9 @@ $user_data = array_merge($user_data, $extra_data);
 $form->setDefaults($user_data);
 
 /*
-==============================================================================
 		FUNCTIONS
-==============================================================================
 */
 
-/*
------------------------------------------------------------
-	LOGIC FUNCTIONS
------------------------------------------------------------
-*/
 
 /**
  * Can a user edit his/her profile?
@@ -497,9 +489,7 @@ function is_profile_editable() {
 }
 
 /*
------------------------------------------------------------
 	PRODUCTIONS FUNCTIONS
------------------------------------------------------------
 */
 
 /**

+ 5 - 0
main/cron/notification.php

@@ -0,0 +1,5 @@
+<?php
+require_once '../inc/global.inc.php';
+require_once api_get_path(LIBRARY_PATH).'notification.lib.php';
+$notify = new Notification();
+$notify->send();

+ 1 - 1
main/inc/banner.inc.php

@@ -133,7 +133,7 @@ if ((api_get_setting('showonline', 'world') == 'true' AND !$_user['user_id']) OR
 	// Display the who's online of the platform
 	if ((api_get_setting('showonline', 'world') == 'true' AND !$_user['user_id']) OR (api_get_setting('showonline', 'users') == 'true' AND $_user['user_id'])) {
 		//echo '<a href="'.api_get_path(WEB_PATH).'whoisonline.php" target="_top" title="'.get_lang('UsersOnline').'" ><img width="12px" src="'.api_get_path(WEB_IMG_PATH).'online.png" title="'.get_lang('UsersOnline').'"> '.get_lang('OnLine').' '.$number.'</a>';
-		echo '<li><a href="'.api_get_path(WEB_PATH).'whoisonline.php" target="_top" title="'.get_lang('UsersOnline').'" ><img width="13px" src="'.api_get_path(WEB_IMG_PATH).'group.gif" title="'.get_lang('UsersOnline').'"> '.$number.'</a></li>';
+		echo '<li><a href="'.api_get_path(WEB_PATH).'whoisonline.php" target="_top" title="'.get_lang('UsersOnline').'" ><img width="13px" src="'.api_get_path(WEB_IMG_PATH).'members.gif" title="'.get_lang('UsersOnline').'"> '.$number.'</a></li>';
 	}
 
 	// Display the who's online for the course

+ 3 - 2
main/inc/lib/database.lib.php

@@ -276,7 +276,7 @@ define('TABLE_THEMATIC','thematic');
 define('TABLE_THEMATIC_PLAN', 'thematic_plan');
 define('TABLE_THEMATIC_ADVANCE','thematic_advance');
 
-
+// Careers, promotions, Usergroups
 define('TABLE_CAREER',      'career');
 define('TABLE_PROMOTION',   'promotion');
 
@@ -285,7 +285,8 @@ define('TABLE_USERGROUP_REL_USER',      'usergroup_rel_user');
 define('TABLE_USERGROUP_REL_COURSE',    'usergroup_rel_course');
 define('TABLE_USERGROUP_REL_SESSION',   'usergroup_rel_session');
 
-
+// Mail notifications
+define('TABLE_NOTIFICATION',               'notification');
 
 /*		DATABASE CLASS
         The class and its methods

+ 21 - 11
main/inc/lib/message.lib.php

@@ -202,7 +202,8 @@ class MessageManager
 	}
 
 	/**
-	 * Save message for social network
+	 * Sends a message to a user/group
+	 * 
 	 * @param int 	  receiver user id
 	 * @param string  subject
 	 * @param string  content
@@ -216,7 +217,7 @@ class MessageManager
 	 */
 	public static function send_message ($receiver_user_id, $subject, $content, $file_attachments = array(), $file_comments = array(), $group_id = 0, $parent_id = 0, $edit_message_id = 0, $sent_email = false) {
         global $charset;
-		$table_message = Database::get_main_table(TABLE_MESSAGE);
+		$table_message      = Database::get_main_table(TABLE_MESSAGE);
         $group_id           = intval($group_id);
         $receiver_user_id   = intval($receiver_user_id);
         $parent_id          = intval($parent_id);
@@ -254,10 +255,9 @@ class MessageManager
 					       " VALUES ('$user_sender_id', '$receiver_user_id', '1', '".api_get_utc_datetime()."','$subject','$content','$group_id','$parent_id', '".api_get_utc_datetime()."')";
 				$result = Database::query($query);
 				$inbox_last_id = Database::insert_id();
-			}
-        
+			}        
 
-			// save attachment file for inbox messages
+			// Save attachment file for inbox messages
 			if (is_array($file_attachments)) {
 				$i = 0;
 				foreach ($file_attachments as $file_attach) {
@@ -270,7 +270,7 @@ class MessageManager
 
 			if (empty($group_id)) {
 				//message in outbox for user friend or group
-				$sql = "INSERT INTO $table_message(user_sender_id, user_receiver_id, msg_status, send_date, title, content, group_id, parent_id, update_date ) ".
+				$sql = "INSERT INTO $table_message (user_sender_id, user_receiver_id, msg_status, send_date, title, content, group_id, parent_id, update_date ) ".
 						 " VALUES ('$user_sender_id', '$receiver_user_id', '4', '".api_get_utc_datetime()."','$subject','$content', '$group_id', '$parent_id', '".api_get_utc_datetime()."')";
 				$rs = Database::query($sql);
 				$outbox_last_id = Database::insert_id();
@@ -286,11 +286,21 @@ class MessageManager
 					}
 				}
 			}
-            
-            //@todo sent email process            
-            if ($sent_email) {            	
-            }
-            
+			
+			//Load user settings
+			require_once api_get_path(LIBRARY_PATH).'notification.lib.php';
+			$notification = new Notification();			    
+		    if (empty($group_id)) {
+                $user_id = $receiver_user_id;
+                $notification->save_message_notifications(array($user_id), $subject,$content);                
+		    } else {
+		        $user_list = GroupPortalManager::get_users_by_group($group_id);
+		        $new_user_list = array();		   
+                foreach($user_list  as $user_data) {
+                    $new_user_list []= $user_data['user_id'];
+                }
+                $notification->save_group_notifications($new_user_list, $subject,$content);                     		
+		    }
 			return $result;
         } else {
         	return get_lang('UserDoesNotExist');

+ 17 - 8
main/inc/lib/model.lib.php

@@ -11,14 +11,23 @@ class Model {
     
     var $table;
     var $columns;
+    // var $pk; some day this will be implemented
     
 	public function __construct() {        
 	}
     
     /**
-     * Useful finder
+     * Useful finder - experimental akelos like only use in notification.lib.php send function
      */
-    public function find() {    	
+    public function find($type, $options = null) {
+        switch($type) {
+            case 'all':
+                return self::get_all($options);
+                break;
+            case (is_numeric($type)) :
+                return self::get($type);
+                break;
+        }
     }    
     
     /**
@@ -63,8 +72,8 @@ class Model {
         return $result;
     }
     
-    public function get_all() {
-        return Database::select('*',$this->table);
+    public function get_all($options = null) {        
+        return Database::select('*',$this->table, $options);
     }
     
     /**
@@ -112,17 +121,17 @@ class Model {
      */
     public function update($params) {
         $params = $this->clean_parameters($params);
-        //If the class have the updated at we update the date
+        //If the class has the updated_at field we update the date
         if (in_array('updated_at', $this->columns)) {           
             $params['updated_at'] = api_get_utc_datetime();
         }
-        //If the class have the created at we remove it
+        //If the class has the created_at field then we remove it
         if (in_array('created_at', $this->columns)) {
             unset($params['created_at']);
         }
         
-        if (!empty($params)) {
-            $id = $params['id'];
+        if (!empty($params) && !empty($params['id'])) {
+            $id = intval($params['id']);
             unset($params['id']); //To not overwrite the id 
             if (is_numeric($id)) {
                 $result = Database::update($this->table, $params, array('id = ?'=>$id));        

+ 168 - 0
main/inc/lib/notification.lib.php

@@ -0,0 +1,168 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+/**
+*	This class provides methods for the Notification management.
+*	Include/require it in your code to use its features.
+*	@package chamilo.library
+*/
+
+require_once 'model.lib.php';
+require_once 'usermanager.lib.php';
+
+//default values
+//mail_notify_message ("At once", "Daily", "No")
+define('NOTIFY_MESSAGE_AT_ONCE',	'1');
+define('NOTIFY_MESSAGE_DAILY',		'8');
+define('NOTIFY_MESSAGE_NO',			'0');
+
+//mail_notify_invitation ("At once", "Daily", "No")
+
+define('NOTIFY_INVITATION_AT_ONCE',	'1');
+define('NOTIFY_INVITATION_DAILY',	'8');
+define('NOTIFY_INVITATION_NO',		'0');
+
+// mail_notify_group_message ("At once", "Daily", "No")
+define('NOTIFY_GROUP_AT_ONCE',		'1');
+define('NOTIFY_GROUP_DAILY',		'8');
+define('NOTIFY_GROUP_NO',			'0');
+
+class Notification extends Model {
+    
+    var $table;
+    var $columns = array('id','dest_user_id','dest_mail','title','content','send_freq','created_at','sent_at');
+    var $max_content_length = 255;
+    var $debug = true;
+    
+	public function __construct() {
+        $this->table =  Database::get_main_table(TABLE_NOTIFICATION);
+	}    
+   
+    public function send($frec = NOTIFY_MESSAGE_DAILY) {
+        $notifications = $this->find('all',array('where'=>array('sent_at IS NULL AND send_freq = ?'=>$frec)));
+        if (!empty($notifications)) {
+            foreach($notifications as $item_to_send) {
+                //Sending email
+                api_send_mail($item_to_send['dest_mail'], $item_to_send['title'], $item_to_send['content']);
+                if ($this->debug) { error_log('Sending message to: '.$item_to_send['dest_mail']); }
+                //Updating
+                $item_to_send['sent_at'] = api_get_utc_datetime();
+                $this->update($item_to_send);
+                //if ($this->debug) { error_log('Updating record : '.print_r($item_to_send,1)); }
+            }
+        }                
+    }
+    
+    /**
+     * Save message notification
+     * @param	array	user list of ids
+     * @param	string	title
+     * @param	string	content of the message
+     * 
+     */
+    public function save_message_notifications($user_list, $title, $content) {
+        if (!empty($user_list)) {            
+            foreach($user_list  as $user_id) {
+                $extra_data = UserManager::get_extra_user_data($user_id);              
+                $params = array();
+                switch ($extra_data['mail_notify_message']) {
+                    case NOTIFY_MESSAGE_NO:
+                        break;
+                    case NOTIFY_MESSAGE_AT_ONCE:                        
+                        $user_info = api_get_user_info($user_id);
+                        if (!empty($user_info['mail'])) {
+                            api_send_mail($user_info['mail'], $title, cut($content, $this->max_content_length));
+                        }
+                        $params['sent_at']       = api_get_utc_datetime();
+                    default:    			        
+                        $extra_data              = UserManager::get_extra_user_data($user_id);
+                        $user_info               = api_get_user_info($user_id);			    
+                	    $params['dest_user_id']  = $user_id;
+                	    $params['dest_mail']     = $user_info['mail'];
+                	    $params['title']         = $title;
+                	    $params['content']       = cut($content, $this->max_content_length);
+                	    $params['send_freq']     = $extra_data['mail_notify_message'];    			 
+                	    $this->save($params);    			        
+                	    break;	   
+                }                   
+            }
+        }
+    }
+    
+    /**
+     * Save invitation notification
+     * @param	array	user list of ids
+     * @param	string	title
+     * @param	string	content of the message
+     * 
+     */
+    public function save_invitation_notifications($user_list, $title, $content) {
+        if (!empty($user_list)) {            
+            foreach($user_list  as $user_id) {                
+                $extra_data = UserManager::get_extra_user_data($user_id);   
+                $params = array();           
+                switch ($extra_data['mail_notify_invitation']) {
+                    case NOTIFY_INVITATION_NO:
+                        break;
+                    case NOTIFY_INVITATION_AT_ONCE:                        
+                        $user_info = api_get_user_info($user_id);
+                        if (!empty($user_info['mail'])) {
+                            api_send_mail($user_info['mail'], $title, cut($content, $this->max_content_length));
+                        }
+                        $params['sent_at']       = api_get_utc_datetime();    
+                    default:    			        
+                        $extra_data              = UserManager::get_extra_user_data($user_id);
+                        $user_info               = api_get_user_info($user_id);			    
+                	    $params['dest_user_id']  = $user_id;
+                	    $params['dest_mail']     = $user_info['mail'];
+                	    $params['title']         = $title;
+                	    $params['content']       = cut($content, $this->max_content_length);
+                	    $params['send_freq']     = $extra_data['mail_notify_invitation'];                    	    		 
+                	    $this->save($params);  			        
+                	    break;	   
+                }                   
+            }
+        }
+    }
+    
+  
+  	/**
+     * Save group notifications
+     * @param	array	user list of ids
+     * @param	string	title
+     * @param	string	content of the message
+     * 
+     */
+    public function save_group_notifications($user_list, $title, $content) {
+        if (!empty($user_list)) {            
+            foreach($user_list  as $user_id) {
+                //Avoiding sending a message to myself    
+                if ($user_id == api_get_user_id()) {
+                    continue;
+                }            
+                $extra_data = UserManager::get_extra_user_data($user_id);   
+                $params = array();           
+                switch ($extra_data['mail_notify_group_message']) {
+                    case NOTIFY_GROUP_NO:
+                        break;
+                    case NOTIFY_GROUP_AT_ONCE:                        
+                        $user_info = api_get_user_info($user_id);
+                        if (!empty($user_info['mail'])) {
+                            api_send_mail($user_info['mail'], $subject, cut($content,150));
+                        }
+                        $params['sent_at']       = api_get_utc_datetime();
+                    default:    			        
+                        $extra_data              = UserManager::get_extra_user_data($user_id);
+                        $user_info               = api_get_user_info($user_id);			    
+                	    $params['dest_user_id']  = $user_id;
+                	    $params['dest_mail']     = $user_info['mail'];
+                	    $params['title']         = $subject;
+                	    $params['content']       = cut($content,150);
+                	    $params['send_freq']     = $extra_data['mail_notify_group_message'];                    	    			 
+                	    $this->save($params);
+                	    break;	   
+                }                   
+            }
+        }
+    }    
+}

+ 7 - 1
main/inc/lib/social.lib.php

@@ -181,8 +181,14 @@ class SocialManager extends UserManager {
 		$row_exist=Database::fetch_array($res_exist,'ASSOC');
 
 		if ($row_exist['count']==0) {
+		    		    
 			$sql='INSERT INTO '.$tbl_message.'(user_sender_id,user_receiver_id,msg_status,send_date,title,content) VALUES('.$user_id.','.$friend_id.','.MESSAGE_STATUS_INVITATION_PENDING.',"'.$current_date.'","'.$message_title.'","'.$message_content.'")';
-			Database::query($sql);
+			Database::query($sql);			
+			
+			require_once api_get_path(LIBRARY_PATH).'notification.lib.php';
+			$notification = new Notification();
+		    $notification->save_invitation_notifications(array($friend_id), $message_title, $message_content);    		
+		    	
 			return true;
 		} else {
 			//invitation already exist

+ 42 - 1
main/install/db_main.sql

@@ -819,7 +819,7 @@ VALUES
 ('enabled_support_pixlr',NULL,'radio','Tools','false','EnabledPixlrTitle','EnabledPixlrComment',NULL,NULL, 0),
 ('show_groups_to_users',NULL,'radio','Platform','true','ShowGroupsToUsersTitle','ShowGroupsToUsersComment',NULL,NULL, 0),
 ('accessibility_font_resize',NULL,'radio','Platform','false','EnableAccessibilityFontResizeTitle','EnableAccessibilityFontResizeComment',NULL,NULL, 1),
-('chamilo_database_version',NULL,'textfield',NULL, '1.8.8.13709','DokeosDatabaseVersion','', NULL, NULL, 0);
+('chamilo_database_version',NULL,'textfield',NULL, '1.8.8.13725','DokeosDatabaseVersion','', NULL, NULL, 0);
 
 UNLOCK TABLES;
 /*!40000 ALTER TABLE settings_current ENABLE KEYS */;
@@ -2549,6 +2549,10 @@ CREATE TABLE course_request (
   UNIQUE KEY code (code)
 );
 
+--
+-- Structure for Careers, Promotions and Usergroups
+--
+
 CREATE TABLE career (
     id INT NOT NULL AUTO_INCREMENT,
     name VARCHAR(255) NOT NULL ,
@@ -2592,3 +2596,40 @@ CREATE TABLE usergroup_rel_session (
     usergroup_id INT NOT NULL,
     session_id  INT NOT NULL
 );
+
+
+--
+-- Structure for Mail notifications
+--
+
+CREATE TABLE notification (
+	id 			BIGINT PRIMARY KEY NOT NULL AUTO_INCREMENT,
+	dest_user_id INT NOT NULL,
+ 	dest_mail 	CHAR(255),
+ 	title 		CHAR(255),
+ 	content 	CHAR(255),
+ 	send_freq 	SMALLINT DEFAULT 1,
+ 	created_at 	DATETIME NOT NULL,
+ 	sent_at 	DATETIME NULL
+);
+
+ALTER TABLE notification ADD index mail_notify_sent_index (sent_at);
+ALTER TABLE notification ADD index mail_notify_freq_index (sent_at, send_freq, created_at);
+
+INSERT INTO user_field (field_type, field_variable, field_display_text, field_visible, field_changeable, field_default_value) values (4, 'mail_notify_invitation',   'MailNotifyInvitation',1,1,'1');
+INSERT INTO user_field (field_type, field_variable, field_display_text, field_visible, field_changeable, field_default_value) values (4, 'mail_notify_message',		 'MailNotifyMessage',1,1,'1');
+INSERT INTO user_field (field_type, field_variable, field_display_text, field_visible, field_changeable, field_default_value) values (4, 'mail_notify_group_message','MailNotifyGroup_message',1,1,'1');
+
+INSERT INTO user_field_options (field_id, option_value, option_display_text, option_order) values (6, '1', 'AtOnce',1);
+INSERT INTO user_field_options (field_id, option_value, option_display_text, option_order) values (6, '8', 'Daily',2);
+INSERT INTO user_field_options (field_id, option_value, option_display_text, option_order) values (6, '0', 'No',3);
+
+INSERT INTO user_field_options (field_id, option_value, option_display_text, option_order) values (7, '1', 'AtOnce',1);
+INSERT INTO user_field_options (field_id, option_value, option_display_text, option_order) values (7, '8', 'Daily',2);
+INSERT INTO user_field_options (field_id, option_value, option_display_text, option_order) values (7, '0', 'No',3);
+
+INSERT INTO user_field_options (field_id, option_value, option_display_text, option_order) values (8, '1', 'AtOnce',1);
+INSERT INTO user_field_options (field_id, option_value, option_display_text, option_order) values (8, '8', 'Daily',2);
+INSERT INTO user_field_options (field_id, option_value, option_display_text, option_order) values (8, '0', 'No',3);
+
+

+ 14 - 1
main/install/migrate-db-1.8.7-1.8.8-pre.sql

@@ -166,10 +166,23 @@ INSERT INTO settings_current (variable, subkey, type, category, selected_value,
 INSERT INTO settings_options (variable, value, display_text) VALUES ('accessibility_font_resize', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('accessibility_font_resize', 'false', 'No');
 
-UPDATE settings_current SET selected_value = '1.8.8.13709' WHERE variable = 'chamilo_database_version';
+
+
+CREATE TABLE notification (	id 			BIGINT PRIMARY KEY NOT NULL AUTO_INCREMENT,	dest_user_id INT NOT NULL, 	dest_mail 	CHAR(255), 	title 		CHAR(255), 	content 	CHAR(255), 	send_freq 	SMALLINT DEFAULT 1, 	created_at 	DATETIME NOT NULL, 	sent_at 	DATETIME NULL);
+
+ALTER TABLE notification ADD index mail_notify_sent_index (sent_at);
+ALTER TABLE notification ADD index mail_notify_freq_index (sent_at, send_freq, created_at);
+
+INSERT INTO user_field (field_type, field_variable, field_display_text, field_visible, field_changeable, field_default_value) values (4, 'mail_notify_invitation',   'MailNotifyInvitation',1,1,'1');
+INSERT INTO user_field (field_type, field_variable, field_display_text, field_visible, field_changeable, field_default_value) values (4, 'mail_notify_message',		 'MailNotifyMessage',1,1,'1');
+INSERT INTO user_field (field_type, field_variable, field_display_text, field_visible, field_changeable, field_default_value) values (4, 'mail_notify_group_message','MailNotifyGroup_message',1,1,'1');
+
+
+UPDATE settings_current SET selected_value = '1.8.8.13725' WHERE variable = 'chamilo_database_version';
 
 -- xxSTATSxx
 ALTER TABLE track_e_exercices ADD COLUMN orig_lp_item_view_id INT NOT NULL DEFAULT 0;
+
 -- xxUSERxx
 ALTER TABLE personal_agenda ADD INDEX idx_personal_agenda_user (user);
 ALTER TABLE personal_agenda ADD INDEX idx_personal_agenda_parent (parent_event_id);

+ 44 - 0
main/install/update-db-1.8.7-1.8.8.inc.php

@@ -249,8 +249,52 @@ if (defined('SYSTEM_INSTALLATION')) {
 
                 }
             }
+            
+            //Adding notifications options
+    
+            $sql = "INSERT INTO $dbNameForm.user_field (field_type, field_variable, field_display_text, field_visible, field_changeable, field_default_value) values (4, 'mail_notify_invitation',   'MailNotifyInvitation',1,1,'1') ";
+            $result = Database::query($sql);
+            $id = Database::insert_id();
+                        
+            $sql = "INSERT INTO $dbNameForm.user_field_options (field_id, option_value, option_display_text, option_order) values ($id, '1', 'AtOnce',1) ";
+            $result = Database::query($sql);
+            $sql = "INSERT INTO $dbNameForm.user_field_options (field_id, option_value, option_display_text, option_order) values ($id, '8', 'Daily',2) ";
+            $result = Database::query($sql);
+            $sql = "INSERT INTO $dbNameForm.user_field_options (field_id, option_value, option_display_text, option_order) values ($id, '0', 'No',3) ";
+            $result = Database::query($sql);         
+                
+            
+            $sql = "INSERT INTO $dbNameForm.user_field (field_type, field_variable, field_display_text, field_visible, field_changeable, field_default_value) values (4, 'mail_notify_message',		 'MailNotifyMessage',1,1,'1')";
+            $result = Database::query($sql);
+            $id = Database::insert_id();
+            
+            $sql = "INSERT INTO $dbNameForm.user_field_options (field_id, option_value, option_display_text, option_order) values ($id, '1', 'AtOnce',1) ";
+            $result = Database::query($sql);
+            $sql = "INSERT INTO $dbNameForm.user_field_options (field_id, option_value, option_display_text, option_order) values ($id, '8', 'Daily',2) ";
+            $result = Database::query($sql);
+            $sql = "INSERT INTO $dbNameForm.user_field_options (field_id, option_value, option_display_text, option_order) values ($id, '0', 'No',3) ";
+            $result = Database::query($sql);
+            
+                        
+            $sql = "INSERT INTO $dbNameForm.user_field (field_type, field_variable, field_display_text, field_visible, field_changeable, field_default_value) values (4, 'mail_notify_group_message','MailNotifyGroupMessage',1,1,'1') ";
+            $result = Database::query($sql);
+            $id = Database::insert_id();
+            
+            $sql = "INSERT INTO $dbNameForm.user_field_options (field_id, option_value, option_display_text, option_order) values ($id, '1', 'AtOnce',1) ";
+            $result = Database::query($sql);
+            $sql = "INSERT INTO $dbNameForm.user_field_options (field_id, option_value, option_display_text, option_order) values ($id, '8', 'Daily',2) ";
+            $result = Database::query($sql);
+            $sql = "INSERT INTO $dbNameForm.user_field_options (field_id, option_value, option_display_text, option_order) values ($id, '0', 'No',3) ";
+            $result = Database::query($sql);
+
+
         }
     }
+    
+    
+
+
+
 
     /* // This fragment of code is not necessary so far.
     // Get the courses databases queries list (c_q_list)

+ 0 - 1
main/messages/new_message.php

@@ -4,7 +4,6 @@
 *	@package chamilo.messages
 */
 
-
 /**
 * This script shows a compose area (wysiwyg editor if supported, otherwise
 * a simple textarea) where the user can type a message.