kannelsms_plugin.class.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /* For licensing terms, see /vendor/license.txt */
  3. /**
  4. * Class KannelsmsPlugin
  5. * This script contains SMS type constants and basic plugin functions
  6. *
  7. * @package chamilo.plugin.kannelsms.lib
  8. * @author Imanol Losada <imanol.losada@beeznest.com>
  9. */
  10. class KannelsmsPlugin extends Plugin
  11. {
  12. const WELCOME_LOGIN_PASSWORD = 0;
  13. const NEW_FILE_SHARED_COURSE_BY = 1;
  14. const ACCOUNT_APPROVED_CONNECT = 2;
  15. const NEW_COURSE_BEEN_CREATED = 3;
  16. const NEW_USER_SUBSCRIBED_COURSE = 4;
  17. const NEW_COURSE_SUGGESTED_TEACHER = 5;
  18. const COURSE_OPENING_REQUEST_CODE_REGISTERED = 6;
  19. const COURSE_OPENING_REQUEST_CODE_APPROVED = 7;
  20. const COURSE_OPENING_REQUEST_CODE_REJECTED = 8;
  21. const COURSE_OPENING_REQUEST_CODE = 9;
  22. const BEEN_SUBSCRIBED_COURSE = 10;
  23. const ASSIGNMENT_BEEN_CREATED_COURSE = 11;
  24. const ACCOUNT_CREATED_UPDATED_LOGIN_PASSWORD = 12;
  25. const PASSWORD_UPDATED_LOGIN_PASSWORD = 13;
  26. const REQUESTED_PASSWORD_CHANGE = 14;
  27. const RECEIVED_NEW_PERSONAL_MESSAGES = 15;
  28. const NEW_USER_PENDING_APPROVAL = 16;
  29. const POSTED_FORUM_COURSE = 17;
  30. const CHECK_EMAIL_CONNECT_MORE_INFO = 18;
  31. const STUDENT_ANSWERED_TEST = 19;
  32. const STUDENT_ANSWERED_TEST_OPEN_QUESTION = 20;
  33. const STUDENT_ANSWERED_TEST_VOICE_QUESTION = 21;
  34. const ANSWER_OPEN_QUESTION_TEST_REVIEWED = 22;
  35. const NEW_THREAD_STARTED_FORUM = 23;
  36. const NEW_ANSWER_POSTED_FORUM = 24;
  37. const NEW_SYSTEM_ANNOUNCEMENT_ADDED = 25;
  38. const TEST_NEW_SYSTEM_ANNOUNCEMENT_ADDED = 26;
  39. const SYSTEM_ANNOUNCEMENT_UPDATE = 27;
  40. const TEST_SYSTEM_ANNOUNCEMENT_UPDATE = 28;
  41. const USER_UPLOADED_ASSIGNMENT_COURSE_STUDENT_SUBMITS_PAPER = 29;
  42. const USER_UPLOADED_ASSIGNMENT_CHECK_STUDENT_SUBMITS_PAPER = 30;
  43. const USER_UPLOADED_ASSIGNMENT_COURSE = 31;
  44. const USER_UPLOADED_ASSIGNMENT_CHECK = 32;
  45. const SUBSCRIBED_SESSION = 33;
  46. const SUBSCRIBED_SESSION_CSV = 34;
  47. const USER_SUGGESTED_BE_FRIENDS = 35;
  48. const USER_ANSWERED_INBOX_MESSAGE = 36;
  49. const BEEN_INVITED_JOIN_GROUP = 37;
  50. const MESSAGES_SENT_EDITED_GROUP_EDITED = 38;
  51. const MESSAGES_SENT_EDITED_GROUP_ADDED = 39;
  52. const BEEN_INVITED_COMPLETE_SURVEY_COURSE = 40;
  53. const REMINDER_ASSIGNMENT_COURSE_DUE = 41;
  54. const USER_DETAILS_MODIFIED = 42;
  55. public $isCoursePlugin = true;
  56. public $isMailPlugin = true;
  57. /**
  58. * create (a singleton function that ensures KannelsmsPlugin instance is
  59. * created only once. If it is already created, it returns the instance)
  60. * @return object KannelsmsPlugin instance
  61. */
  62. public static function create()
  63. {
  64. static $result = null;
  65. return $result ? $result : $result = new self();
  66. }
  67. /**
  68. * Constructor
  69. * @return void
  70. */
  71. protected function __construct()
  72. {
  73. $fields = array(
  74. 'tool_enable' => 'boolean',
  75. 'hostAddress' => 'text',
  76. 'username' => 'text',
  77. 'password' => 'text',
  78. 'from' => 'text'
  79. );
  80. $smsTypeOptions = $this->getSmsTypeOptions();
  81. foreach ($smsTypeOptions as $smsTypeOption) {
  82. $fields[$smsTypeOption] = 'checkbox';
  83. }
  84. parent::__construct('0.1', 'Imanol Losada', $fields);
  85. }
  86. /**
  87. * addMobilePhoneNumberField (adds a mobile phone number field if it is not
  88. * already created)
  89. * @return void
  90. */
  91. private function addMobilePhoneNumberField()
  92. {
  93. $result = Database::select('mobile_phone_number', 'user_field');
  94. if (empty($result)) {
  95. require_once api_get_path(LIBRARY_PATH).'extra_field.lib.php';
  96. $extraField = new Extrafield('user');
  97. $extraField->save(array(
  98. 'field_type' => 1,
  99. 'field_variable' => 'mobile_phone_number',
  100. 'field_display_text' => $this->get_lang('mobile_phone_number'),
  101. 'field_default_value' => null,
  102. 'field_order' => 2,
  103. 'field_visible' => 1,
  104. 'field_changeable' => 1,
  105. 'field_filter' => null
  106. ));
  107. }
  108. }
  109. /**
  110. * getSmsTypeOptions (returns all SMS types)
  111. * @return array SMS types
  112. */
  113. private function getSmsTypeOptions()
  114. {
  115. return array(
  116. 'MessageWelcomeXLoginXPasswordX',
  117. 'MessageXNewFileSharedCourseXByX',
  118. 'MessageXAccountApprovedConnectX',
  119. 'MessageXNewCourseXBeenCreatedX',
  120. 'MessageXNewUserXSubscribedCourseX',
  121. 'MessageXNewCourseSuggestedTeacherX',
  122. 'MessageXCourseOpeningRequestCodeXRegistered',
  123. 'MessageXCourseOpeningRequestCourseCodeXApproved',
  124. 'MessageXRequestOpenCourseCodeXReject',
  125. 'MessageXCourseOpeningRequestCourseCodeX',
  126. 'MessageXBeenSubscribedCourseX',
  127. 'MessageXAssignmentBeenCreatedCourseX',
  128. 'MessageXAccountCreatedUpdatedLoginXPasswordX',
  129. 'MessageXPasswordUpdatedLoginXPasswordX',
  130. 'MessageXRequestedPasswordChange',
  131. 'MessageXReceivedNewPersonalMessages',
  132. 'MessageXNewUserXPendingApproval',
  133. 'MessageXXPostedForumXCourseX',
  134. 'MessageXXXCheckEmailConnectMoreInfo',
  135. 'MessageXXStudentXAnsweredTestX',
  136. 'MessageXXStudentXAnsweredTestXOpenQuestion',
  137. 'MessageXXStudentXAnsweredTestXVoiceQuestion',
  138. 'MessageXXAnswerOpenQuestionTestXReviewed',
  139. 'MessageXXNewThreadXStartedForumX',
  140. 'MessageXXNewAnswerPostedXForumX',
  141. 'MessageXXNewSystemAnnouncementAdded',
  142. 'MessageXTestXNewSystemAnnouncementAdded',
  143. 'MessageXXSystemAnnouncementUpdate',
  144. 'MessageXTestXSystemAnnouncementUpdate',
  145. 'MessageXUserXUploadedAssignmentXCourseXStudentSubmitsPaper',
  146. 'MessageXUserXUploadedAssignmentXCheckXStudentSubmitsPaper',
  147. 'MessageXUserXUploadedAssignmentXCourseX',
  148. 'MessageXUserXUploadedAssignmentXCheckX',
  149. 'MessageXSubscribedSessionX',
  150. 'MessageXSubscribedSessionXCSV',
  151. 'MessageXUserXSuggestedBeFriends',
  152. 'MessageXUserXAnsweredInboxMessage',
  153. 'MessageXBeenInvitedJoinGroupX',
  154. 'MessageXMessagesSentEditedGroupXEdited',
  155. 'MessageXMessagesSentEditedGroupXAdded',
  156. 'MessageXBeenInvitedCompleteSurveyXCourseX',
  157. 'MessageXReminderAssignmentXCourseXDue',
  158. 'MessageXUserDetailsModified'
  159. );
  160. }
  161. /**
  162. * install (installs the plugin)
  163. * @return void
  164. */
  165. public function install()
  166. {
  167. $this->addMobilePhoneNumberField();
  168. }
  169. /**
  170. * install (uninstalls the plugin and removes all plugin's tables and/or rows)
  171. * @return void
  172. */
  173. public function uninstall()
  174. {
  175. $tSettings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  176. $sql = "DELETE FROM $tSettings WHERE subkey = 'kannelsms'";
  177. Database::query($sql);
  178. }
  179. }