course_request.lib.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Course request manager
  5. * @package chamilo.library
  6. *
  7. * @author José Manuel Abuin Mosquera <chema@cesga.es>, 2010
  8. * @author Bruno Rubio Gayo <brubio@cesga.es>, 2010
  9. * Centro de Supercomputacion de Galicia (CESGA)
  10. *
  11. * @author Ivan Tcholakov <ivantcholakov@gmail.com> (technical adaptation for Chamilo 1.8.8), 2010
  12. */
  13. /**
  14. * Code
  15. */
  16. /**
  17. * Course request manager
  18. * @package chamilo.library
  19. */
  20. class CourseRequestManager {
  21. /**
  22. * Checks whether a given course code has been already occupied.
  23. * @param string $wanted_course_code The code to be checked.
  24. * @return string
  25. * Returns TRUE if there is created:
  26. * - a course with the same code OR visual_code (visualcode).
  27. * - a course request with the same code as the given one, or
  28. * Othewise returns FALSE.
  29. */
  30. public static function course_code_exists($wanted_course_code) {
  31. if ($code_exists = CourseManager::course_code_exists($wanted_course_code)) {
  32. return $code_exists;
  33. }
  34. $table_course_request = Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST);
  35. $wanted_course_code = Database::escape_string($wanted_course_code);
  36. $sql = sprintf('SELECT COUNT(id) AS number FROM %s WHERE visual_code = "%s"', $table_course_request, $wanted_course_code);
  37. $result = Database::fetch_array(Database::query($sql));
  38. return $result['number'] > 0;
  39. }
  40. /**
  41. * Creates a new course request within the database.
  42. * @param string $wanted_code The code for the created in the future course.
  43. * @param string $title
  44. * @param string $description
  45. * @param string $category_code
  46. * @param string $course_language
  47. * @param string $objetives
  48. * @param string $target_audience
  49. * @param int/string $user_id
  50. * @return int/bool The database id of the newly created course request or FALSE on failure.
  51. */
  52. public static function create_course_request($wanted_code, $title, $description, $category_code, $course_language, $objetives, $target_audience, $user_id, $exemplary_content) {
  53. $wanted_code = trim($wanted_code);
  54. $user_id = (int)$user_id;
  55. $exemplary_content = (bool)$exemplary_content ? 1 : 0;
  56. if ($wanted_code == '') {
  57. return false;
  58. }
  59. if (self::course_code_exists($wanted_code)) {
  60. return false;
  61. }
  62. if ($user_id <= 0) {
  63. return false;
  64. }
  65. $user_info = api_get_user_info($user_id);
  66. if (!is_array($user_info)) {
  67. return false;
  68. }
  69. $tutor_name = api_get_person_name($user_info['firstname'], $user_info['lastname'], null, null, $course_language);
  70. $request_date = api_get_utc_datetime();
  71. $status = COURSE_REQUEST_PENDING;
  72. $info = 0;
  73. $keys = CourseManager::define_course_keys($wanted_code, '');
  74. if (!count($keys)) {
  75. return false;
  76. }
  77. $visual_code = $keys['currentCourseCode'];
  78. $code = $keys['currentCourseId'];
  79. $db_name = $keys['currentCourseDbName'];
  80. $directory = $keys['currentCourseRepository'];
  81. $sql = sprintf('INSERT INTO %s (
  82. code, user_id, directory, db_name,
  83. course_language, title, description, category_code,
  84. tutor_name, visual_code, request_date,
  85. objetives, target_audience, status, info, exemplary_content)
  86. VALUES (
  87. "%s", "%s", "%s", "%s",
  88. "%s", "%s", "%s", "%s",
  89. "%s", "%s", "%s",
  90. "%s", "%s", "%s", "%s", "%s");', Database::get_main_table(TABLE_MAIN_COURSE_REQUEST),
  91. Database::escape_string($code), Database::escape_string($user_id), Database::escape_string($directory), Database::escape_string($db_name),
  92. Database::escape_string($course_language), Database::escape_string($title), Database::escape_string($description), Database::escape_string($category_code),
  93. Database::escape_string($tutor_name), Database::escape_string($visual_code), Database::escape_string($request_date),
  94. Database::escape_string($objetives), Database::escape_string($target_audience), Database::escape_string($status), Database::escape_string($info), Database::escape_string($exemplary_content));
  95. $result_sql = Database::query($sql);
  96. if (!$result_sql) {
  97. return false;
  98. }
  99. $last_insert_id = Database::insert_id();
  100. // E-mail notifications.
  101. // E-mail language: The platform language seems to be the best choice.
  102. //$email_language = $course_language;
  103. //$email_language = api_get_interface_language();
  104. $email_language = api_get_setting('platformLanguage');
  105. $email_subject = sprintf(get_lang('CourseRequestEmailSubject', null, $email_language), '['.api_get_setting('siteName').']', $code);
  106. $email_body = get_lang('CourseRequestMailOpening', null, $email_language)."\n\n";
  107. $email_body .= get_lang('CourseName', null, $email_language).': '.$title."\n";
  108. $email_body .= get_lang('Fac', null, $email_language).': '.$category_code."\n";
  109. $email_body .= get_lang('CourseCode', null, $email_language).': '.$code."\n";
  110. $email_body .= get_lang('Professor', null, $email_language).': '.api_get_person_name($user_info['firstname'], $user_info['lastname'], null, null, $email_language)."\n";
  111. $email_body .= get_lang('Email', null, $email_language).': '.$user_info['mail']."\n";
  112. $email_body .= get_lang('Description', null, $email_language).': '.$description."\n";
  113. $email_body .= get_lang('Objectives', null, $email_language).': '.$objetives."\n";
  114. $email_body .= get_lang('TargetAudience', null, $email_language).': '.$target_audience."\n";
  115. $email_body .= get_lang('Ln', null, $email_language).': '.$course_language."\n";
  116. $email_body .= get_lang('FillWithExemplaryContent', null, $email_language).': '.($exemplary_content ? get_lang('Yes', null, $email_language) : get_lang('No', null, $email_language))."\n";
  117. // Sending an e-mail to the platform administrator.
  118. $email_body_admin = $email_body;
  119. $email_body_admin .= "\n".get_lang('CourseRequestPageForApproval', null, $email_language).' '.api_get_path(WEB_CODE_PATH).'admin/course_request_edit.php?id='.$last_insert_id."\n";
  120. $email_body_admin .= "\n".get_lang('CourseRequestLegalNote', null, $email_language)."\n";
  121. $sender_name_teacher = api_get_person_name($user_info['firstname'], $user_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS);
  122. $sender_email_teacher = $user_info['mail'];
  123. $recipient_name_admin = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
  124. $recipient_email_admin = api_get_setting('emailAdministrator');
  125. @api_mail($recipient_name_admin, $recipient_email_admin, $email_subject, $email_body_admin, $sender_name_teacher, $sender_email_teacher);
  126. // Sending an e-mail to the requestor.
  127. $email_body_teacher = get_lang('Dear', null, $email_language).' ';
  128. $email_body_teacher .= api_get_person_name($user_info['firstname'], $user_info['lastname'], null, null, $email_language).",\n\n";
  129. $email_body_teacher .= $email_body;
  130. $email_body_teacher .= "\n".get_lang('Formula', null, $email_language)."\n";
  131. $email_body_teacher .= api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, null, $email_language)."\n";
  132. $email_body_teacher .= get_lang('Manager', null, $email_language).' '.api_get_setting('siteName')."\n";
  133. $email_body_teacher .= get_lang('Phone', null, $email_language).': '.api_get_setting('administratorTelephone')."\n";
  134. $email_body_teacher .= get_lang('Email', null, $email_language).': '.api_get_setting('emailAdministrator', null, $email_language)."\n";
  135. $email_body_teacher .= "\n".get_lang('CourseRequestLegalNote', null, $email_language)."\n";
  136. // Swap the sender and the recipient.
  137. $sender_name_admin = $recipient_name_admin;
  138. $sender_email_admin = $recipient_email_admin;
  139. $recipient_name_teacher = $sender_name_teacher;
  140. $recipient_email_teacher = $sender_email_teacher;
  141. @api_mail($recipient_name_teacher, $recipient_email_teacher, $email_subject, $email_body_teacher, $sender_name_admin, $sender_email_admin);
  142. return $last_insert_id;
  143. }
  144. /**
  145. * Updates a given course request in the database.
  146. * @param int/string $id The id (an integer number) of the corresponding database record.
  147. * @param string $wanted_code The code for the created in the future course.
  148. * @param string $title
  149. * @param string $description
  150. * @param string $category_code
  151. * @param string $course_language
  152. * @param string $objetives
  153. * @param string $target_audience
  154. * @param int/string $user_id
  155. * @return bool Returns TRUE on success or FALSE on failure.
  156. */
  157. public static function update_course_request($id, $wanted_code, $title, $description, $category_code, $course_language, $objetives, $target_audience, $user_id, $exemplary_content) {
  158. $id = (int)$id;
  159. $wanted_code = trim($wanted_code);
  160. $user_id = (int)$user_id;
  161. $exemplary_content = (bool)$exemplary_content ? 1 : 0;
  162. if ($wanted_code == '') {
  163. return false;
  164. }
  165. if ($user_id <= 0) {
  166. return false;
  167. }
  168. // Retrieve request's data
  169. $course_request_info = self::get_course_request_info($id);
  170. if (!is_array($course_request_info)) {
  171. return false;
  172. }
  173. $code = $wanted_code;
  174. $tutor_name = $course_request_info['tutor_name'];
  175. $directory = $course_request_info['directory'];
  176. $db_name = $course_request_info['db_name'];
  177. $visual_code = $course_request_info['visual_code'];
  178. $request_date = $course_request_info['request_date'];
  179. $status = $course_request_info['status'];
  180. $info = $course_request_info['info'];
  181. if ($wanted_code != $course_request_info['code']) {
  182. if (self::course_code_exists($wanted_code)) {
  183. return false;
  184. }
  185. $keys = CourseManager::define_course_keys($wanted_code, '');
  186. if (count($keys)) {
  187. $visual_code = $keys['currentCourseCode'];
  188. $code = $keys['currentCourseId'];
  189. $db_name = $keys['currentCourseDbName'];
  190. $directory = $keys['currentCourseRepository'];
  191. } else {
  192. return false;
  193. }
  194. }
  195. if ($user_id != $course_request_info['code']) {
  196. $user_info = api_get_user_info($user_id);
  197. if (is_array($user_info)) {
  198. $tutor_name = api_get_person_name($user_info['firstname'], $user_info['lastname'], null, null, $course_language);
  199. } else {
  200. $user_id = $course_request_info['code'];
  201. }
  202. }
  203. if ($course_language != $course_request_info['course_language']) {
  204. $user_info = api_get_user_info($user_id);
  205. if (is_array($user_info)) {
  206. $tutor_name = api_get_person_name($user_info['firstname'], $user_info['lastname'], null, null, $course_language);
  207. }
  208. }
  209. $sql = sprintf('UPDATE %s SET
  210. code = "%s", user_id = "%s", directory = "%s", db_name = "%s",
  211. course_language = "%s", title = "%s", description = "%s", category_code = "%s",
  212. tutor_name = "%s", visual_code = "%s", request_date = "%s",
  213. objetives = "%s", target_audience = "%s", status = "%s", info = "%s", exemplary_content = "%s"
  214. WHERE id = '.$id, Database::get_main_table(TABLE_MAIN_COURSE_REQUEST),
  215. Database::escape_string($code), Database::escape_string($user_id), Database::escape_string($directory), Database::escape_string($db_name),
  216. Database::escape_string($course_language), Database::escape_string($title), Database::escape_string($description), Database::escape_string($category_code),
  217. Database::escape_string($tutor_name), Database::escape_string($visual_code), Database::escape_string($request_date),
  218. Database::escape_string($objetives), Database::escape_string($target_audience), Database::escape_string($status), Database::escape_string($info), Database::escape_string($exemplary_content));
  219. $result_sql = Database::query($sql);
  220. return $result_sql !== false;
  221. }
  222. /**
  223. * Deletes a given course request.
  224. * @param int/string $id The id (an integer number) of the corresponding database record.
  225. * @return bool Returns TRUE on success or FALSE on failure.
  226. */
  227. public static function delete_course_request($id) {
  228. $id = (int)$id;
  229. $sql = "DELETE FROM ".Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST)." WHERE id = ".$id;
  230. $result = Database::query($sql);
  231. return $result !== false;
  232. }
  233. public static function count_course_requests($status = null) {
  234. $course_table = Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST);
  235. if (is_null($status)) {
  236. $sql = "SELECT COUNT(id) AS number FROM ".$course_table;
  237. } else {
  238. $status = (int)$status;
  239. $sql = "SELECT COUNT(id) AS number FROM ".$course_table." WHERE status = ".$status;
  240. }
  241. $result = Database::fetch_array(Database::query($sql));
  242. if (is_array($result)) {
  243. return $result['number'];
  244. }
  245. return false;
  246. }
  247. /**
  248. * Gets all the information about a course request using its database id as an access key.
  249. * @param int/string $id The id (an integer number) of the corresponding database record.
  250. * @return array/bool Returns the requested data as an array or FALSE on failure.
  251. */
  252. public static function get_course_request_info($id) {
  253. $id = (int)$id;
  254. $sql = "SELECT * FROM ".Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST)." WHERE id = ".$id;
  255. $result = Database::query($sql);
  256. if (Database::num_rows($result) > 0) {
  257. return Database::fetch_array($result);
  258. }
  259. return false;
  260. }
  261. /**
  262. * Gets the code of a given course request using its database id as an access key.
  263. * @param int/string $id The id (an integer number) of the corresponding database record.
  264. * @return string/bool Returns the requested requested code or FALSE on failure.
  265. */
  266. public static function get_course_request_code($id) {
  267. $id = (int)$id;
  268. $sql = "SELECT code FROM ".Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST)." WHERE id = ".$id;
  269. $result = Database::query($sql);
  270. if (Database::num_rows($result) > 0) {
  271. $result_array = Database::fetch_array($result, 'NUM');
  272. if (is_array($result_array)) {
  273. return $result_array[0];
  274. }
  275. }
  276. return false;
  277. }
  278. /**
  279. * Accepts a given by its id course request. The requested course gets created immediately after the request acceptance.
  280. * @param int/string $id The id (an integer number) of the corresponding database record.
  281. * @return string/bool Returns the code of the newly created course or FALSE on failure.
  282. */
  283. public static function accept_course_request($id) {
  284. $id = (int)$id;
  285. // Retrieve request's data
  286. $course_request_info = self::get_course_request_info($id);
  287. if (!is_array($course_request_info)) {
  288. return false;
  289. }
  290. // Make all the checks again before the new course creation.
  291. if (CourseManager::course_code_exists($wanted_code)) {
  292. return false;
  293. }
  294. $user_id = (int)$course_request_info['user_id'];
  295. if ($user_id <= 0) {
  296. return false;
  297. }
  298. $user_info = api_get_user_info($user_id);
  299. if (!is_array($user_info)) {
  300. return false;
  301. }
  302. // Create the requested course
  303. $params = array();
  304. $params['title'] = $course_request_info['title'];
  305. $params['category_code'] = $course_request_info['category_code'];
  306. $params['course_language'] = $course_request_info['course_language'];
  307. $params['exemplary_content'] = intval($course_request_info['exemplary_content']) > 0;
  308. $params['wanted_code'] = $course_request_info['code'];
  309. $params['user_id'] = $course_request_info['user_id'];
  310. $params['tutor_name'] = api_get_person_name($user_info['firstname'], $user_info['lastname'], null, null, $course_language);
  311. $course_info = CourseManager::create_course($params);
  312. if (!empty($course_info)) {
  313. // Mark the request as accepted.
  314. $sql = "UPDATE ".Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST)." SET status = ".COURSE_REQUEST_ACCEPTED." WHERE id = ".$id;
  315. Database::query($sql);
  316. // E-mail notification.
  317. // E-mail language: The platform language seems to be the best choice
  318. $email_language = api_get_setting('platformLanguage');
  319. $email_subject = sprintf(get_lang('CourseRequestAcceptedEmailSubject', null, $email_language), '['.api_get_setting('siteName').']', $course_info['code']);
  320. $email_body = get_lang('Dear', null, $email_language).' ';
  321. $email_body .= api_get_person_name($user_info['firstname'], $user_info['lastname'], null, null, $email_language).",\n\n";
  322. $email_body .= sprintf(get_lang('CourseRequestAcceptedEmailText', null, $email_language), $wanted_code, $course_info['code'], api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/')."\n";
  323. $email_body .= "\n".get_lang('Formula', null, $email_language)."\n";
  324. $email_body .= api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, null, $email_language)."\n";
  325. $email_body .= get_lang('Manager', null, $email_language).' '.api_get_setting('siteName')."\n";
  326. $email_body .= get_lang('Phone', null, $email_language).': '.api_get_setting('administratorTelephone')."\n";
  327. $email_body .= get_lang('Email', null, $email_language).': '.api_get_setting('emailAdministrator', null, $email_language)."\n";
  328. $email_body .= "\n".get_lang('CourseRequestLegalNote', null, $email_language)."\n";
  329. $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
  330. $sender_email = api_get_setting('emailAdministrator');
  331. $recipient_name = api_get_person_name($user_info['firstname'], $user_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS);
  332. $recipient_email = $user_info['mail'];
  333. $extra_headers = 'Bcc: '.$sender_email;
  334. @api_mail($recipient_name, $recipient_email, $email_subject, $email_body, $sender_name, $sender_email);
  335. return $course_info['code'];
  336. }
  337. return false;
  338. }
  339. /**
  340. * Rejects a given course request.
  341. * @param int/string $id The id (an integer number) of the corresponding database record.
  342. * @return bool Returns TRUE on success or FALSE on failure.
  343. */
  344. public static function reject_course_request($id) {
  345. $id = (int)$id;
  346. // Retrieve request's data
  347. $course_request_info = self::get_course_request_info($id);
  348. if (!is_array($course_request_info)) {
  349. return false;
  350. }
  351. $user_id = intval($course_request_info['user_id']);
  352. if ($user_id <= 0) {
  353. return false;
  354. }
  355. $user_info = api_get_user_info($user_id);
  356. if (!is_array($user_info)) {
  357. return false;
  358. }
  359. $code = $course_request_info['code'];
  360. $sql = "UPDATE ".Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST)." SET status = ".COURSE_REQUEST_REJECTED." WHERE id = ".$id;
  361. if (Database::query($sql) === false) {
  362. return false;
  363. }
  364. // E-mail notification.
  365. // E-mail language: The platform language seems to be the best choice.
  366. //$email_language = $course_language;
  367. //$email_language = api_get_interface_language();
  368. $email_language = api_get_setting('platformLanguage');
  369. $email_subject = sprintf(get_lang('CourseRequestRejectedEmailSubject', null, $email_language), '['.api_get_setting('siteName').']', $code);
  370. $email_body = get_lang('Dear', null, $email_language).' ';
  371. $email_body .= api_get_person_name($user_info['firstname'], $user_info['lastname'], null, null, $email_language).",\n\n";
  372. $email_body .= sprintf(get_lang('CourseRequestRejectedEmailText', null, $email_language), $code)."\n";
  373. $email_body .= "\n".get_lang('Formula', null, $email_language)."\n";
  374. $email_body .= api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, null, $email_language)."\n";
  375. $email_body .= get_lang('Manager', null, $email_language).' '.api_get_setting('siteName')."\n";
  376. $email_body .= get_lang('Phone', null, $email_language).': '.api_get_setting('administratorTelephone')."\n";
  377. $email_body .= get_lang('Email', null, $email_language).': '.api_get_setting('emailAdministrator', null, $email_language)."\n";
  378. $email_body .= "\n".get_lang('CourseRequestLegalNote', null, $email_language)."\n";
  379. $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
  380. $sender_email = api_get_setting('emailAdministrator');
  381. $recipient_name = api_get_person_name($user_info['firstname'], $user_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS);
  382. $recipient_email = $user_info['mail'];
  383. $extra_headers = 'Bcc: '.$sender_email;
  384. @api_mail($recipient_name, $recipient_email, $email_subject, $email_body, $sender_name, $sender_email);
  385. return true;
  386. }
  387. /**
  388. * Asks the author (through e-mail) for additional information about the given course request.
  389. * @param int/string $id The database primary id of the given request.
  390. * @return bool Returns TRUE on success or FALSE on failure.
  391. */
  392. public static function ask_for_additional_info($id) {
  393. $id = (int)$id;
  394. // Retrieve request's data
  395. $course_request_info = self::get_course_request_info($id);
  396. if (!is_array($course_request_info)) {
  397. return false;
  398. }
  399. $user_id = intval($course_request_info['user_id']);
  400. if ($user_id <= 0) {
  401. return false;
  402. }
  403. $user_info = api_get_user_info($user_id);
  404. if (!is_array($user_info)) {
  405. return false;
  406. }
  407. $code = $course_request_info['code'];
  408. $info = intval($course_request_info['info']);
  409. // Error is to be returned on a repeated attempt for asking additional information.
  410. if (!empty($info)) {
  411. return false;
  412. }
  413. // E-mail notification.
  414. // E-mail language: The platform language seems to be the best choice.
  415. //$email_language = $course_language;
  416. //$email_language = api_get_interface_language();
  417. $email_language = api_get_setting('platformLanguage');
  418. $email_subject = sprintf(get_lang('CourseRequestAskInfoEmailSubject', null, $email_language), '['.api_get_setting('siteName').']', $code);
  419. $email_body = get_lang('Dear', null, $email_language).' ';
  420. $email_body .= api_get_person_name($user_info['firstname'], $user_info['lastname'], null, null, $email_language).",\n\n";
  421. $email_body .= sprintf(get_lang('CourseRequestAskInfoEmailText', null, $email_language), $code)."\n";
  422. $email_body .= "\n".get_lang('Formula', null, $email_language)."\n";
  423. $email_body .= api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, null, $email_language)."\n";
  424. $email_body .= get_lang('Manager', null, $email_language).' '.api_get_setting('siteName')."\n";
  425. $email_body .= get_lang('Phone', null, $email_language).': '.api_get_setting('administratorTelephone')."\n";
  426. $email_body .= get_lang('Email', null, $email_language).': '.api_get_setting('emailAdministrator', null, $email_language)."\n";
  427. $email_body .= "\n".get_lang('CourseRequestLegalNote', null, $email_language)."\n";
  428. $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
  429. $sender_email = api_get_setting('emailAdministrator');
  430. $recipient_name = api_get_person_name($user_info['firstname'], $user_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS);
  431. $recipient_email = $user_info['mail'];
  432. $extra_headers = 'Bcc: '.$sender_email;
  433. $result = @api_mail($recipient_name, $recipient_email, $email_subject, $email_body, $sender_name, $sender_email);
  434. if (!$result) {
  435. return false;
  436. }
  437. // Marking the fact that additional information about the request has been asked.
  438. $sql = "UPDATE ".Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST)." SET info = 1 WHERE id = ".$id;
  439. $result = Database::query($sql) !== false;
  440. return $result;
  441. }
  442. /**
  443. * Checks whether additional information about the given course request has been asked.
  444. * @param int/string $id The database primary id of the given request.
  445. * @return bool Returns TRUE if additional information has been asked or FALSE otherwise.
  446. */
  447. public static function additional_info_asked($id) {
  448. $id = (int)$id;
  449. $sql = "SELECT id FROM ".Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST)." WHERE (id = ".$id." AND info > 0)";
  450. $result = Database::num_rows(Database::query($sql));
  451. return !empty($result);
  452. }
  453. }