clockworksms_plugin.class.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /* For licensing terms, see /vendor/license.txt */
  3. /**
  4. * Class ClockworksmsPlugin
  5. * This script contains SMS type constants and basic plugin functions
  6. *
  7. * @package chamilo.plugin.clockworksms.lib
  8. * @author Imanol Losada <imanol.losada@beeznest.com>
  9. */
  10. class ClockworksmsPlugin 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 ClockworksmsPlugin instance is
  59. * created only once. If it is already created, it returns the instance)
  60. * @return object ClockworksmsPlugin 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('tool_enable' => 'boolean', 'api_key' => 'text');
  74. $smsTypeOptions = $this->getSmsTypeOptions();
  75. foreach ($smsTypeOptions as $smsTypeOption) {
  76. $fields[$smsTypeOption] = 'checkbox';
  77. }
  78. parent::__construct('0.1', 'Imanol Losada', $fields);
  79. }
  80. /**
  81. * addMobilePhoneNumberField (adds a mobile phone number field if it is not
  82. * already created)
  83. * @return void
  84. */
  85. private function addMobilePhoneNumberField()
  86. {
  87. $result = Database::select('mobile_phone_number', 'user_field');
  88. if (empty($result)) {
  89. require_once api_get_path(LIBRARY_PATH).'extra_field.lib.php';
  90. $extraField = new Extrafield('user');
  91. $extraField->save(array(
  92. 'field_type' => 1,
  93. 'field_variable' => 'mobile_phone_number',
  94. 'field_display_text' => $this->get_lang('mobile_phone_number'),
  95. 'field_default_value' => null,
  96. 'field_order' => 2,
  97. 'field_visible' => 1,
  98. 'field_changeable' => 1,
  99. 'field_filter' => null
  100. ));
  101. }
  102. }
  103. /**
  104. * getSmsTypeOptions (returns all SMS types)
  105. * @return array SMS types
  106. */
  107. private function getSmsTypeOptions()
  108. {
  109. return array(
  110. 'MessageWelcomeXLoginXPasswordX',
  111. 'MessageXNewFileSharedCourseXByX',
  112. 'MessageXAccountApprovedConnectX',
  113. 'MessageXNewCourseXBeenCreatedX',
  114. 'MessageXNewUserXSubscribedCourseX',
  115. 'MessageXNewCourseSuggestedTeacherX',
  116. 'MessageXCourseOpeningRequestCodeXRegistered',
  117. 'MessageXCourseOpeningRequestCourseCodeXApproved',
  118. 'MessageXRequestOpenCourseCodeXReject',
  119. 'MessageXCourseOpeningRequestCourseCodeX',
  120. 'MessageXBeenSubscribedCourseX',
  121. 'MessageXAssignmentBeenCreatedCourseX',
  122. 'MessageXAccountCreatedUpdatedLoginXPasswordX',
  123. 'MessageXPasswordUpdatedLoginXPasswordX',
  124. 'MessageXRequestedPasswordChange',
  125. 'MessageXReceivedNewPersonalMessages',
  126. 'MessageXNewUserXPendingApproval',
  127. 'MessageXXPostedForumXCourseX',
  128. 'MessageXXXCheckEmailConnectMoreInfo',
  129. 'MessageXXStudentXAnsweredTestX',
  130. 'MessageXXStudentXAnsweredTestXOpenQuestion',
  131. 'MessageXXStudentXAnsweredTestXVoiceQuestion',
  132. 'MessageXXAnswerOpenQuestionTestXReviewed',
  133. 'MessageXXNewThreadXStartedForumX',
  134. 'MessageXXNewAnswerPostedXForumX',
  135. 'MessageXXNewSystemAnnouncementAdded',
  136. 'MessageXTestXNewSystemAnnouncementAdded',
  137. 'MessageXXSystemAnnouncementUpdate',
  138. 'MessageXTestXSystemAnnouncementUpdate',
  139. 'MessageXUserXUploadedAssignmentXCourseXStudentSubmitsPaper',
  140. 'MessageXUserXUploadedAssignmentXCheckXStudentSubmitsPaper',
  141. 'MessageXUserXUploadedAssignmentXCourseX',
  142. 'MessageXUserXUploadedAssignmentXCheckX',
  143. 'MessageXSubscribedSessionX',
  144. 'MessageXSubscribedSessionXCSV',
  145. 'MessageXUserXSuggestedBeFriends',
  146. 'MessageXUserXAnsweredInboxMessage',
  147. 'MessageXBeenInvitedJoinGroupX',
  148. 'MessageXMessagesSentEditedGroupXEdited',
  149. 'MessageXMessagesSentEditedGroupXAdded',
  150. 'MessageXBeenInvitedCompleteSurveyXCourseX',
  151. 'MessageXReminderAssignmentXCourseXDue',
  152. 'MessageXUserDetailsModified'
  153. );
  154. }
  155. /**
  156. * install (installs the plugin)
  157. * @return void
  158. */
  159. public function install()
  160. {
  161. $this->addMobilePhoneNumberField();
  162. }
  163. /**
  164. * install (uninstalls the plugin and removes all plugin's tables and/or rows)
  165. * @return void
  166. */
  167. public function uninstall()
  168. {
  169. $tSettings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  170. $sql = "DELETE FROM $tSettings WHERE subkey = 'clockworksms'";
  171. Database::query($sql);
  172. }
  173. }