Browse Source

Extra fields are available before creating a user. Add 'getSMSPluginName' function. Now 'sms_type' is got dynamically. Edit translation files - refs BT#8939

Imanol Losada 10 years ago
parent
commit
1c747e518e

+ 10 - 5
main/admin/user_add.php

@@ -312,7 +312,14 @@ if( $form->validate()) {
             $username = $email;
         }
 
-		$user_id = UserManager::create_user($firstname, $lastname, $status, $email, $username, $password, $official_code, $language, $phone, null, $auth_source, $expiration_date, $active, $hr_dept_id, null, null, $send_mail);
+        $extra = array();
+        foreach ($user as $key => $value) {
+            if (substr($key, 0, 6) == 'extra_') { //an extra field
+                $extra[substr($key, 6)] = $value;
+            }
+        }
+
+		$user_id = UserManager::create_user($firstname, $lastname, $status, $email, $username, $password, $official_code, $language, $phone, null, $auth_source, $expiration_date, $active, $hr_dept_id, $extra, null, $send_mail);
 
 		Security::clear_token();
 		$tok = Security::get_token();
@@ -330,10 +337,8 @@ if( $form->validate()) {
 				UserManager::update_user($user_id, $firstname, $lastname, $username, $password, $auth_source, $email, $status, $official_code, $phone, $picture_uri, $expiration_date, $active, null, $hr_dept_id, null, $language);
 			}
 
-			foreach ($user as $key => $value) {
-				if (substr($key, 0, 6) == 'extra_') { //an extra field
-					UserManager::update_extra_field_value($user_id, substr($key, 6), $value);
-				}
+			foreach ($extra as $key => $value) {
+				UserManager::update_extra_field_value($user_id, $key, $value);
 			}
 			if ($platform_admin) {
                 UserManager::add_user_as_admin($user_id);

+ 2 - 1
main/dropbox/dropbox_functions.inc.php

@@ -879,8 +879,9 @@ function store_add_dropbox()
     if ($b_send_mail) {
         foreach ($new_work_recipients as $recipient_id) {
             $recipent_temp = UserManager :: get_user_info_by_id($recipient_id);
+            $plugin = new AppPlugin();
             $additionalParameters = array(
-                'smsType' => ClockworksmsPlugin::NEW_FILE_SHARED_COURSE_BY,
+                'smsType' => constant($plugin->getSMSPluginName().'::NEW_FILE_SHARED_COURSE_BY'),
                 'userId' => $recipient_id,
                 'courseTitle' => $_course['title'],
                 'userUsername' => $recipent_temp['username']

+ 2 - 1
main/inc/ajax/user_manager.ajax.php

@@ -95,8 +95,9 @@ switch ($action) {
                     //$emailbody.=get_lang('Problem'). "\n\n". get_lang('SignatureFormula');
                     $emailbody.=api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator');
 
+                    $plugin = new AppPlugin();
                      $additionalParameters = array(
-                        'smsType' => ClockworksmsPlugin::ACCOUNT_APPROVED_CONNECT,
+                        'smsType' => constant($plugin->getSMSPluginName().'::ACCOUNT_APPROVED_CONNECT'),
                         'userId' => $user_id
                     );
 

+ 2 - 1
main/inc/lib/add_course.lib.inc.php

@@ -2915,8 +2915,9 @@ function register_course($params)
                 $message .= get_lang('Language').' '.$course_language;
 
                 $userInfo = api_get_user_info($user_id);
+                $plugin = new AppPlugin();
                 $additionalParameters = array(
-                    'smsType' => ClockworksmsPlugin::NEW_COURSE_BEEN_CREATED,
+                    'smsType' => constant($plugin->getSMSPluginName().'::NEW_COURSE_BEEN_CREATED'),
                     'userId' => $user_id,
                     'courseName' => $title,
                     'creatorUsername' => $userInfo['username']

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

@@ -6050,8 +6050,9 @@ function api_send_mail($to, $subject, $message, $additional_headers = null, $add
     $installedPluginsList = $plugin->getInstalledPluginListObject();
     foreach ($installedPluginsList as $installedPlugin) {
         if ($installedPlugin->isMailPlugin and array_key_exists("smsType", $additionalParameters)) {
-            $clockworksmsObject = new Clockworksms();
-            $clockworksmsObject->send($additionalParameters);
+            $className = str_replace("Plugin", "", get_class($installedPlugin));
+            $smsObject = new $className;
+            $smsObject->send($additionalParameters);
         }
     }
 

+ 2 - 1
main/inc/lib/course.lib.php

@@ -2616,8 +2616,9 @@ class CourseManager
             $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
             $email_admin = api_get_setting('emailAdministrator');
 
+            $plugin = new AppPlugin();
             $additionalParameters = array(
-                'smsType' => ClockworksmsPlugin::NEW_USER_SUBSCRIBED_COURSE,
+                'smsType' => constant($plugin->getSMSPluginName().'::NEW_USER_SUBSCRIBED_COURSE'),
                 'userId' => $tutor['user_id'],
                 'userUsername' => $student['username'],
                 'courseCode' => $course_code

+ 10 - 5
main/inc/lib/course_request.lib.php

@@ -149,8 +149,10 @@ class CourseRequestManager
         $recipient_email_admin = get_setting('emailAdministrator');
 
         $userInfo = api_get_user_info($user_id);
+        $plugin = new AppPlugin();
+        $className = $plugin->getSMSPluginName();
         $additionalParameters = array(
-            'smsType' => ClockworksmsPlugin::NEW_COURSE_SUGGESTED_TEACHER,
+            'smsType' => constant($className.'::NEW_COURSE_SUGGESTED_TEACHER'),
             'userId' => $user_id,
             'userUsername' => $userInfo['username']
         );
@@ -187,7 +189,7 @@ class CourseRequestManager
         $recipient_email_teacher = $sender_email_teacher;
 
         $additionalParameters = array(
-            'smsType' => ClockworksmsPlugin::COURSE_OPENING_REQUEST_CODE_REGISTERED,
+            'smsType' => constant($className.'::COURSE_OPENING_REQUEST_CODE_REGISTERED'),
             'userId' => $user_info['user_id'],
             'courseCode' => $wanted_code
         );
@@ -467,8 +469,9 @@ class CourseRequestManager
             $recipient_email = $user_info['mail'];
             $extra_headers = 'Bcc: '.$sender_email;
 
+            $plugin = new AppPlugin();
             $additionalParameters = array(
-                'smsType' => ClockworksmsPlugin::COURSE_OPENING_REQUEST_CODE_APPROVED,
+                'smsType' => constant($plugin->getSMSPluginName().'::COURSE_OPENING_REQUEST_CODE_APPROVED'),
                 'userId' => $user_id,
                 'courseCode' => $course_info['code']
             );
@@ -545,8 +548,9 @@ class CourseRequestManager
         $recipient_email = $user_info['mail'];
         $extra_headers = 'Bcc: '.$sender_email;
 
+        $plugin = new AppPlugin();
         $additionalParameters = array(
-            'smsType' => ClockworksmsPlugin::COURSE_OPENING_REQUEST_CODE_REJECTED,
+            'smsType' => constant($plugin->getSMSPluginName().'::COURSE_OPENING_REQUEST_CODE_REJECTED'),
             'userId' => $user_id,
             'courseCode' => $code
         );
@@ -622,8 +626,9 @@ class CourseRequestManager
         $recipient_email = $user_info['mail'];
         $extra_headers = 'Bcc: '.$sender_email;
 
+        $plugin = new AppPlugin();
         $additionalParameters = array(
-            'smsType' => ClockworksmsPlugin::COURSE_OPENING_REQUEST_CODE,
+            'smsType' => constant($plugin->getSMSPluginName().'::COURSE_OPENING_REQUEST_CODE'),
             'userId' => $user_id,
             'courseCode' => $code
         );

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

@@ -227,8 +227,9 @@ function api_mail_html(
     $installedPluginsList = $plugin->getInstalledPluginListObject();
     foreach ($installedPluginsList as $installedPlugin) {
         if ($installedPlugin->isMailPlugin and array_key_exists("smsType", $additionalParameters)) {
-            $clockworksmsObject = new Clockworksms();
-            $clockworksmsObject->send($additionalParameters);
+            $className = str_replace("Plugin", "", get_class($installedPlugin));
+            $smsObject = new $className;
+            $smsObject->send($additionalParameters);
         }
     }
 

+ 14 - 0
main/inc/lib/plugin.lib.php

@@ -586,4 +586,18 @@ class AppPlugin
             }
         }
     }
+
+    /**
+     * Get first SMS plugin name
+     * @return string|boolean
+     */
+    public function getSMSPluginName() {
+        $installedPluginsList = $this->getInstalledPluginListObject();
+        foreach ($installedPluginsList as $installedPlugin) {
+            if ($installedPlugin->isMailPlugin) {
+                return get_class($installedPlugin);
+            }
+        }
+        return false;
+    }
 }

+ 2 - 1
main/inc/lib/usermanager.lib.php

@@ -212,8 +212,9 @@ class UserManager
                     EventsDispatcher::events('user_registration', $values);
                 } else {
                     $phoneNumber = isset($extra['mobile_phone_number']) ? $extra['mobile_phone_number'] : null;
+                    $plugin = new AppPlugin();
                     $additionalParameters = array(
-                        'smsType' => ClockworksmsPlugin::WELCOME_LOGIN_PASSWORD,
+                        'smsType' => constant($plugin->getSMSPluginName().'::WELCOME_LOGIN_PASSWORD'),
                         'userId' => $return,
                         'mobilePhoneNumber' => $phoneNumber,
                         'password' => $original_password

+ 2 - 1
main/user/user_add.php

@@ -202,8 +202,9 @@ if($register) {
             $message = stripslashes(api_get_person_name($firstname_form, $lastname_form))." ".get_lang('AddedU');
         }
 
+        $plugin = new AppPlugin();
         $additionalParameters = array(
-            'smsType' => ClockworksmsPlugin::BEEN_SUBSCRIBED_COURSE,
+            'smsType' => constant($plugin->getSMSPluginName().'::BEEN_SUBSCRIBED_COURSE'),
             'userId' => $user_id,
             'courseTitle' => $currentCourseName
         );

+ 2 - 1
main/work/work.lib.php

@@ -2541,8 +2541,9 @@ function send_email_on_homework_creation($course_id)
                 $emailbody .= get_lang('HomeworkHasBeenCreatedForTheCourse')." ".$course_id.". "."\n\n".get_lang('PleaseCheckHomeworkPage');
                 $emailbody .= "\n\n".api_get_person_name($currentUser["firstname"], $currentUser["lastname"]);
 
+                $plugin = new AppPlugin();
                 $additionalParameters = array(
-                    'smsType' => ClockworksmsPlugin::ASSIGNMENT_BEEN_CREATED_COURSE,
+                    'smsType' => constant($plugin->getSMSPluginName().'::ASSIGNMENT_BEEN_CREATED_COURSE'),
                     'userId' => $student["user_id"],
                     'courseTitle' => $course_id
                 );

+ 9 - 6
plugin/kannelsms/lang/english.php

@@ -1,17 +1,20 @@
 <?php
 
-$strings['plugin_title']        = "SMS Sending";
+$strings['plugin_title']        = "Kannel SMS";
 $strings['plugin_comment']      = "When enabled and an email sent successfully, a text message is sent to the user.";
 
-$strings['api_key'] = "Kannel SMS key";
-$strings['api_key_help'] = "This is the Kannel SMS server security key. <a target='_blank' href='http://www.kannelsms.com/platforms/chamilo/'>Click here</a> to get it.";
-
 $strings['tool_enable'] = "Enable SMS sending";
 $strings['tool_enable_help'] = "Choose if you want to enable SMS sending tool.
     Once enabled, they will be sent along with an email the selected SMS message types to the users who had filled their mobile phone number field in their profile<br />";
 
-$strings['type'] = "Send SMS when";
-$strings['mobile_phone_number'] = "Mobile Phone (include country dialing code only)";
+$strings['hostAddress'] = "Host address";
+$strings['hostAddress_help'] = "This is the address where your SMS gateway is hosted. Example: http://mobilegateway.com/tools/gateways/smssender";
+$strings['username'] = "Username";
+$strings['password'] = "Password";
+$strings['from'] = "Sender mobile number";
+
+$strings['sms_types'] = "Send SMS when";
+$strings['mobile_phone_number'] = "Mobile";
 
 $strings['MessageWelcomeXLoginXPasswordX']                              = "A user is added to the platform";
 $strings['MessageXNewFileSharedCourseXByX']                             = "A file is added to dropbox";

+ 8 - 5
plugin/kannelsms/lang/spanish.php

@@ -1,17 +1,20 @@
 <?php
 
-$strings['plugin_title']        = "Envío de SMS";
+$strings['plugin_title']        = "Kannel SMS";
 $strings['plugin_comment']      = "Ofrece la posibilidad de enviar SMS a celulares cuando se envían e-mails de notificación.";
 
-$strings['api_key'] = "Clave Kannel SMS";
-$strings['api_key_help'] = "Ésta es la clave de seguridad de su servidor Kannel SMS. Para obtenerla, <a target='_blank' href='http://www.kannelsms.com/platforms/chamilo/'>haga click aquí</a>";
-
 $strings['tool_enable'] = "Activar envío de SMS";
 $strings['tool_enable_help'] = "Escoja si desea activar la herramienta de envío de mensajes a celulares Kannel SMS.
     Una vez activada, se enviarán, simultaneamente con los correos, los tipos mensajes SMS seleccionados a los usuarios que hayan especificado un número de celular en su perfil.<br />";
 
+$strings['hostAddress'] = "Dirección del servidor";
+$strings['hostAddress_help'] = "Ésta es la dirección en donde se aloja su pasarela de SMS. Ejemplo: http://mobilegateway.com/tools/gateways/smssender";
+$strings['username'] = "Nombre de usuario";
+$strings['password'] = "Contraseña";
+$strings['from'] = "Número de móvil remitente";
+
 $strings['sms_types'] = "Enviar un SMS cuando";
-$strings['mobile_phone_number'] = "Celular (incluya sólo el código de llamada del país)";
+$strings['mobile_phone_number'] = "Móvil";
 
 $strings['MessageWelcomeXLoginXPasswordX']                              = "Se añada un usuario a la plataforma";
 $strings['MessageXNewFileSharedCourseXByX']                             = "Un archivo se añada a dropbox";

+ 18 - 29
plugin/kannelsms/lib/kannelsms.lib.php

@@ -13,8 +13,11 @@
 
 class Kannelsms
 {
-    public $apiKey;
     public $api;
+    public $hostAddress;
+    public $username;
+    public $password;
+    public $from;
     public $plugin_enabled = false;
 
     /**
@@ -26,34 +29,13 @@ class Kannelsms
     {
         $plugin = KannelsmsPlugin::create();
         $kannelSMSPlugin = $plugin->get('tool_enable');
-        if (empty($apiKey)) {
-            $kannelSMSApiKey = $plugin->get('api_key');
-        } else {
-            $kannelSMSApiKey = $apiKey;
-        }
         $this->table = Database::get_main_table('user_field_values');
         if ($kannelSMSPlugin == true) {
-            $this->apiKey = $kannelSMSApiKey;
-            // Setting Kannelsms api
-            define('CONFIG_SECURITY_API_KEY', $this->apiKey);
-            $trimmedApiKey = trim(CONFIG_SECURITY_API_KEY);
-            if (!empty($trimmedApiKey)) {
-                $this->api = new Kannel(CONFIG_SECURITY_API_KEY);
-            } else {
-                $this->api = new Kannel(' ');
-                $recipient_name = api_get_person_name(
-                    api_get_setting('administratorName'),
-                    api_get_setting('administratorSurname'),
-                    null,
-                    PERSON_NAME_EMAIL_ADDRESS
-                );
-                $email_form = get_setting('emailAdministrator');
-                $emailsubject = 'Kannelsms error';
-                $emailbody = 'Key cannot be blank';
-                $sender_name = $recipient_name;
-                $email_admin = $email_form;
-                api_mail_html($recipient_name, $email_form, $emailsubject, $emailbody, $sender_name, $email_admin);
-            }
+            $this->api = new Kannel(' ');
+            $this->hostAddress = $plugin->get('hostAddress');
+            $this->username = $plugin->get('username');
+            $this->password = $plugin->get('password');
+            $this->from = $plugin->get('from');
             $this->plugin_enabled = true;
         }
     }
@@ -101,7 +83,14 @@ class Kannelsms
             );
 
             if (!empty($message['message'])) {
-                $result = $this->api->send($message);
+                if(extension_loaded('curl')) {
+                    $url = $this->hostAddress.'?username='.
+                        $this->username.'&password='.$this->password.'&from='.
+                        $this->from.'&to='.$message['to'].'&msg='.urlencode($message['message']);
+                    $ch = curl_init($url);
+                    curl_exec($ch);
+                    curl_close($ch);
+                }
 
                 // Commented for future message logging / tracking purposes
                 /*if( $result["success"] ) {
@@ -166,7 +155,7 @@ class Kannelsms
         $tool_name = $plugin->get_lang('plugin_title');
         $tpl = new Template($tool_name);
 
-        switch (constant('KannelsmsPlugin::'.$additionalParameters['smsType'])) {
+        switch ($additionalParameters['smsType']) {
             case KannelsmsPlugin::WELCOME_LOGIN_PASSWORD:
                 $userInfo = api_get_user_info($additionalParameters['userId']);
                 return $this->buildSms(

+ 7 - 1
plugin/kannelsms/lib/kannelsms_plugin.class.php

@@ -74,7 +74,13 @@ class KannelsmsPlugin extends Plugin
      */
     protected function __construct()
     {
-        $fields = array('tool_enable' => 'boolean', 'api_key' => 'text');
+        $fields = array(
+            'tool_enable' => 'boolean',
+            'hostAddress' => 'text',
+            'username' => 'text',
+            'password' => 'text',
+            'from' => 'text'
+        );
         $smsTypeOptions = $this->getSmsTypeOptions();
         foreach ($smsTypeOptions as $smsTypeOption) {
             $fields[$smsTypeOption] = 'checkbox';