BMLT Root Server
c_comdef_admin_ajax_handler.class.php
Go to the documentation of this file.
1 <?php
2 /*
3  This file is part of the Basic Meeting List Toolbox (BMLT).
4 
5  Find out more at: https://bmlt.app
6 
7  BMLT is free software: you can redistribute it and/or modify
8  it under the terms of the MIT License.
9 
10  BMLT is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  MIT License for more details.
14 
15  You should have received a copy of the MIT License along with this code.
16  If not, see <https://opensource.org/licenses/MIT>.
17 */
18 defined('BMLT_EXEC') or die('Cannot Execute Directly'); // Makes sure that this file is in the correct context.
19 require_once(dirname(__FILE__).'/../../server/c_comdef_server.class.php');
20 require_once(dirname(__FILE__).'/../../server/shared/classes/comdef_utilityclasses.inc.php');
21 require_once(dirname(__FILE__).'/../../server/shared/Array2Json.php');
22 require_once(dirname(__FILE__).'/../../server/shared/Array2XML.php');
23 require_once(dirname(__FILE__).'/../../client_interface/csv/search_results_csv.php');
24 require_once(dirname(__FILE__).'/PhpJsonXmlArrayStringInterchanger.inc.php');
25 
26 /***********************************************************************************************************//**
27  \class c_comdef_admin_main_console
28  \brief Controls display of the main BMLT administration console.
29 ***************************************************************************************************************/
30 // phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
31 // phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
33 // phpcs:enable PSR1.Classes.ClassDeclaration.MissingNamespace
34 // phpcs:enable Squiz.Classes.ValidClassName.NotCamelCaps
35 {
36  public $my_localized_strings; ///< This will contain the localized strings and whatnot for display.
37  public $my_server; ///< This hold the server object.
38  public $my_user; ///< This holds the instance of the logged-in user.
39  public $my_http_vars; ///< Contains the HTTP vars sent in.
40 
41  /*******************************************************************************************************//**
42  \brief
43  ***********************************************************************************************************/
44  public function __construct( $in_http_vars ///< The HTTP transaction parameters
45  )
46  {
47  $this->my_http_vars = $in_http_vars;
48  $this->my_localized_strings = c_comdef_server::GetLocalStrings();
49  $this->my_server = c_comdef_server::MakeServer();
50  $this->my_user = $this->my_server->GetCurrentUserObj();
51 
52  // We check this every chance that we get.
53  if (!$this->my_user || ($this->my_user->GetUserLevel() == _USER_LEVEL_DISABLED)) {
54  die('NOT AUTHORIZED');
55  }
56  }
57 
58  /*******************************************************************************************************//**
59  \brief
60  \returns
61  ***********************************************************************************************************/
62  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
63  public function parse_ajax_call()
64  {
65  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
66  $returned_text = '';
67 
68  $account_changed = false;
69 
70  if (isset($this->my_http_vars['set_format_change']) && $this->my_http_vars['set_format_change']) {
71  $this->HandleFormatChange($this->my_http_vars['set_format_change']);
72  }
73  if (isset($this->my_http_vars['delete_format']) && $this->my_http_vars['delete_format']) {
74  $this->HandleDeleteFormat($this->my_http_vars['delete_format']);
75  } elseif (isset($this->my_http_vars['create_new_user']) && $this->my_http_vars['create_new_user']) {
76  $this->HandleUserCreate($this->my_http_vars['create_new_user']);
77  } elseif (isset($this->my_http_vars['set_user_change']) && $this->my_http_vars['set_user_change']) {
78  $this->HandleUserChange($this->my_http_vars['set_user_change']);
79  } elseif (isset($this->my_http_vars['delete_user']) && $this->my_http_vars['delete_user']) {
80  $this->HandleDeleteUser($this->my_http_vars['delete_user'], isset($this->my_http_vars['permanently']));
81  } elseif (isset($this->my_http_vars['create_new_service_body']) && $this->my_http_vars['create_new_service_body']) {
82  $this->HandleServiceBodyCreate($this->my_http_vars['create_new_service_body']);
83  } elseif (isset($this->my_http_vars['set_service_body_change']) && $this->my_http_vars['set_service_body_change']) {
84  $this->HandleServiceBodyChange($this->my_http_vars['set_service_body_change']);
85  } elseif (isset($this->my_http_vars['delete_service_body']) && $this->my_http_vars['delete_service_body']) {
86  $this->HandleDeleteServiceBody($this->my_http_vars['delete_service_body'], isset($this->my_http_vars['permanently']));
87  } elseif (isset($this->my_http_vars['set_meeting_change']) && $this->my_http_vars['set_meeting_change']) {
88  $this->HandleMeetingUpdate($this->my_http_vars['set_meeting_change']);
89  } elseif (isset($this->my_http_vars['delete_meeting']) && $this->my_http_vars['delete_meeting']) {
90  $returned_text = $this->HandleDeleteMeeting($this->my_http_vars['delete_meeting']);
91  } elseif (isset($this->my_http_vars['get_meeting_history']) && $this->my_http_vars['get_meeting_history']) {
92  $returned_text = $this->GetMeetingHistory($this->my_http_vars['get_meeting_history']);
93  } elseif (isset($this->my_http_vars['do_meeting_search'])) {
94  $used_formats = array();
95  $returned_text = $this->TranslateToJSON($this->GetSearchResults($this->my_http_vars, $used_formats));
96  header('Content-Type:application/json; charset=UTF-8');
97  } elseif (isset($this->my_http_vars['do_update_world_ids'])) {
98  $returned_text = $this->HandleMeetingWorldIDsUpdate();
99  } elseif (isset($this->my_http_vars['do_naws_import'])) {
100  $returned_text = $this->HandleNAWSImport();
101  } else {
102  $this->HandleAccountChange();
103  }
104 
105  return $returned_text;
106  }
107 
108  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
109  public function HandleNAWSImport()
110  {
111  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
112  if (!c_comdef_server::IsUserServerAdmin(null, true)) {
113  return 'NOT AUTHORIZED';
114  }
115 
116  $ret = array(
117  'success' => false,
118  'errors' => null,
119  'report' => array(
120  'num_service_bodies_created' => 0,
121  'num_users_created' => 0,
122  'num_meetings_created' => 0
123  )
124  );
125 
126  if (empty($_FILES)) {
127  $ret['errors'] = $this->my_localized_strings['comdef_server_admin_strings']['server_admin_error_no_files_uploaded'];
128  return json_encode($ret);
129  }
130 
131  require_once(__DIR__.'/NAWSImport.php');
132  require_once(__DIR__.'/NAWSImportServiceBodiesExistException.php');
133  require_once(__DIR__.'/NAWSImportMeetingsExistException.php');
134 
135  try {
136  $nawsImport = new NAWSImport($_FILES['thefile']['tmp_name'], $this->my_http_vars['initialValueForPublished'] == 'TRUE');
137  $nawsImport->import(true);
139  $ret['errors'] = $this->my_localized_strings['comdef_server_admin_strings']['server_admin_error_service_bodies_already_exist'] . implode(', ', $e->getWorldIds());
140  return json_encode($ret);
141  } catch (NAWSImportMeetingsExistException $e) {
142  $ret['errors'] = $this->my_localized_strings['comdef_server_admin_strings']['server_admin_error_meetings_already_exist'] . implode(', ', $e->getWorldIds());
143  return json_encode($ret);
144  } catch (Exception $e) {
145  $ret['errors'] = $e->getMessage();
146  return json_encode($ret);
147  }
148 
149  $ret['success'] = true;
150  $ret['report']['num_service_bodies_created'] = $nawsImport->getNumServiceBodiesCreated();
151  $ret['report']['num_users_created'] = $nawsImport->getNumUsersCreated();
152  $ret['report']['num_meetings_created'] = $nawsImport->getNumMeetingsCreated();
153 
154  return json_encode($ret);
155  }
156 
157  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
158  public function HandleMeetingWorldIDsUpdate()
159  {
160  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
161  $ret = array(
162  'success' => false,
163  'errors' => array(),
164  'report' => array(
165  'updated' => array(),
166  'not_updated' => array(),
167  'not_found' => array()
168  )
169  );
170 
171  $isServerAdmin = c_comdef_server::IsUserServerAdmin(null, true);
172  if (!$isServerAdmin && !c_comdef_server::IsUserServiceBodyAdmin(null, true)) {
173  return 'NOT AUTHORIZED';
174  }
175 
176  if (empty($_FILES)) {
177  $ret['errors'][] = $this->my_localized_strings['comdef_server_admin_strings']['server_admin_error_no_files_uploaded'];
178  return json_encode($ret);
179  }
180 
181  require_once(__DIR__ .'/../../vendor/autoload.php');
182 
183  $file = $_FILES['thefile'];
184  try {
185  $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReaderForFile($file['tmp_name']);
186  $spreadsheet = $reader->load($file['tmp_name']);
187  $rows = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
188  } catch (Exception $e) {
189  $ret['errors'][] = $this->my_localized_strings['comdef_server_admin_strings']['server_admin_error_could_not_create_reader'] . $e->getMessage();
190  return json_encode($ret);
191  }
192 
193  if (!$isServerAdmin) {
194  // We are a service body admin, so get the meeting IDs this admin is allowed to edit
195  $userMeetingIDs = array();
196  $userServiceBodyIDs = c_comdef_server::GetUserServiceBodies();
197  if (is_array($userServiceBodyIDs)) {
198  $userServiceBodyIDs = array_keys($userServiceBodyIDs);
199  foreach ($userServiceBodyIDs as $serviceBodyID) {
200  $sbMeetings = c_comdef_server::GetMeetingsForAServiceBody($serviceBodyID);
201  if ($sbMeetings) {
202  $sbMeetings = $sbMeetings->GetMeetingObjects();
203  if (is_array($sbMeetings)) {
204  foreach ($sbMeetings as $meeting) {
205  $userMeetingIDs[$meeting->GetID()] = null;
206  }
207  }
208  }
209  }
210  }
211  }
212 
213  $bmltIdx = "";
214  $worldIdx = "";
215  $meetingMap = array();
216  for ($i = 1; $i <= count($rows); $i++) {
217  $row = $rows[$i];
218  if ($i == 1) {
219  foreach ($row as $key => $value) {
220  if ($value == "bmlt_id") {
221  $bmltIdx = $key;
222  } elseif ($value == "Committee") {
223  $worldIdx = $key;
224  }
225  if ($bmltIdx && $worldIdx) {
226  break;
227  }
228  }
229 
230  if (!$bmltIdx || !$worldIdx) {
231  if (!$bmltIdx) {
232  $ret['errors'][] = $this->my_localized_strings['comdef_server_admin_strings']['server_admin_error_required_spreadsheet_column'] . "bmlt_id";
233  }
234  if (!$worldIdx) {
235  $ret['errors'][] = $this->my_localized_strings['comdef_server_admin_strings']['server_admin_error_required_spreadsheet_column'] . "Committee";
236  }
237  return json_encode($ret);
238  }
239 
240  continue;
241  }
242 
243  $bmltId = trim(strval($row[$bmltIdx]));
244  $worldId = trim($row[$worldIdx]);
245  if (empty($bmltId) && empty($worldId)) {
246  continue;
247  } elseif (!is_numeric($bmltId)) {
248  $ret['errors'][] = $this->my_localized_strings['comdef_server_admin_strings']['server_admin_error_bmlt_id_not_integer'] . $bmltId;
249  } elseif ($isServerAdmin || array_key_exists(intval($bmltId), $userMeetingIDs)) {
250  $meetingMap[$bmltId] = $worldId;
251  }
252  }
253 
254  if (empty($meetingMap)) {
255  $ret['errors'][] = $this->my_localized_strings['comdef_server_admin_strings']['server_admin_error_no_world_ids_updated'];
256  }
257 
258  if (!empty($ret['errors'])) {
259  return json_encode($ret);
260  }
261 
262  // Attempt to save some memory, as many servers will be memory restricted
263  unset($rows);
264  unset($spreadsheet);
265  unset($reader);
266 
267  $json_tool = new PhpJsonXmlArrayStringInterchanger;
268  $used_formats = array();
269  $meetings = $this->GetSearchResults(array('meeting_ids' => array_keys($meetingMap)), $used_formats);
270  $meetings = $this->TranslateToJSON($meetings);
271  $meetings = $json_tool->convertJsonToArray($meetings, true);
272  $map = array();
273  foreach ($meetings as $meeting) {
274  $bmltId = strval($meeting['id_bigint']);
275  $map[$bmltId] = $meeting;
276  }
277  $meetings = $map;
278 
280  try {
281  foreach ($meetingMap as $bmltId => $newWorldId) {
282  if (!array_key_exists($bmltId, $meetings)) {
283  $ret['report']['not_found'][] = $bmltId;
284  continue;
285  }
286 
287  $meeting = $meetings[$bmltId];
288  $oldWorldId = $meeting['worldid_mixed'];
289  if ($oldWorldId == $newWorldId) {
290  $ret['report']['not_updated'][] = $bmltId;
291  continue;
292  }
293 
294  $meeting['worldid_mixed'] = $newWorldId;
295  $this->SetMeetingDataValues($meeting, false);
296  $ret['report']['updated'][] = $bmltId;
297  }
298  } catch (Exception $e) {
300  throw $e;
301  }
303 
304  $ret['success'] = empty($ret['errors']);
305  return json_encode($ret);
306  }
307 
308  /*******************************************************************/
309  /**
310  \brief
311  */
312  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
313  public function HandleAccountChange()
314  {
315  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
316  $response_text = array();
317 
318  $t_user = isset($this->my_http_vars['target_user']) ? intval($this->my_http_vars['target_user']) : 0;
319 
320  if ((intval($this->my_user->GetID()) == $t_user) && isset($this->my_http_vars['account_email_value'])) {
321  $this->my_user->SetEmailAddress($this->my_http_vars['account_email_value']);
322  $success = $this->my_user->UpdateToDB();
323  $response_text['EMAIL_CHANGED'] = ($success ? true : false);
324  }
325 
326  if ((intval($this->my_user->GetID()) == $t_user) && isset($this->my_http_vars['account_description_value'])) {
327  $this->my_user->SetLocalDescription($this->my_http_vars['account_description_value']);
328  $success = $this->my_user->UpdateToDB();
329  $response_text['DESCRIPTION_CHANGED'] = ($success ? true : false);
330  }
331 
332  $login = $this->my_user->GetLogin();
333  $login_changed = false;
334  $password = (isset($this->my_http_vars['account_password_value']) ? $this->my_http_vars['account_password_value'] : '');
335 
336  if ($this->my_user->GetUserLevel() == _USER_LEVEL_SERVER_ADMIN) {
337  if ((intval($this->my_user->GetID()) == $t_user) && isset($this->my_http_vars['account_name_value'])) {
338  $this->my_user->SetLocalName($this->my_http_vars['account_name_value']);
339  $success = $this->my_user->UpdateToDB();
340  $response_text['NAME_CHANGED'] = ($success ? true : false);
341  }
342 
343  if ((intval($this->my_user->GetID()) == $t_user) && isset($this->my_http_vars['account_login_value'])) {
344  $login = $this->my_http_vars['account_login_value'];
345  $login_changed = true;
346  }
347  } else {
348  unset($this->my_http_vars['account_login_value']);
349  }
350 
351  if ((intval($this->my_user->GetID()) == $t_user) && (isset($this->my_http_vars['account_login_value']) || isset($this->my_http_vars['account_password_value']))) {
352  $success = $this->my_user->UpdateToDB(false, $login, $password);
353  $response_text['PASSWORD_CHANGED'] = ($success ? true : false);
354  if ($login_changed) {
355  $response_text['LOGIN_CHANGED'] = ($success ? true : false);
356  }
357  }
358 
359  if (is_array($response_text) && count($response_text)) {
360  header('Content-Type:application/json; charset=UTF-8');
361  echo ( array2json(array ( 'ACCOUNT_CHANGED' => $response_text )));
362  }
363  }
364 
365  /*******************************************************************/
366  /**
367  \brief
368  */
369  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
370  public function HandleFormatChange( $in_new_format_data ///< A JSON string with the new format data.
371  )
372  {
373  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
374  if (c_comdef_server::IsUserServerAdmin(null, true)) {
375  $json_tool = new PhpJsonXmlArrayStringInterchanger;
376 
377  $the_processed_formats = $json_tool->convertJsonToArray($in_new_format_data, true);
378 
379  $the_changed_formats = array();
380  foreach ($the_processed_formats as $the_format) {
381  if (trim($the_format['key']) || trim($the_format['name']) || trim($the_format['description'])) {
382  $the_changed_formats[$the_format['lang_key']] = $the_format;
383  }
384  }
385 
386  $the_objects_to_be_changed = array();
387 
388  $ret_data = '';
389  $shared_id = '';
390  $format_type = 'FC1';
391 
392  // The first thing that we do, is go through the incoming data, and make sure that we create or modify c_comdef_format objects to match the input.
393  foreach ($the_changed_formats as $format_data) {
394  if ($format_data) {
395  foreach ($format_data as &$data_val) { // This removes double-slashes, added by the JSON encoding.
396  $data_val = str_replace('\\\\', '\\', $data_val);
397  }
398 
399  if (!$shared_id) {
400  $shared_id = intval($format_data['shared_id']);
401  $format_type = $format_data['type'];
402  } else {
403  if ($shared_id != intval($format_data['shared_id'])) { // This should never happen.
404  $the_objects_to_be_changed = null;
405  break;
406  }
407  }
408 
409  $lang_key = $format_data['lang_key'];
410 
411  $server_format = null;
412 
413  if ($format_data['shared_id']) {
414  $this->my_server->GetOneFormat($format_data['shared_id'], $format_data['lang_key']);
415  }
416  if (!($server_format instanceof c_comdef_format)) {
417  $parent = null;
418  $server_format = new c_comdef_format($parent, $format_data['shared_id'], $format_type, $format_data['key'], null, null, $format_data['lang_key'], $format_data['name'], $format_data['description']);
419  } else {
420  $server_format->SetKey($format_data['key']);
421  $server_format->SetLocalName($format_data['name']);
422  $server_format->SetLocalDescription($format_data['description']);
423  }
424 
425  if (isset($format_data['worldid_mixed']) && $format_data['worldid_mixed']) {
426  $server_format->SetWorldID($format_data['worldid_mixed']);
427  }
428 
429  array_push($the_objects_to_be_changed, $server_format);
430  }
431  }
432 
433  $the_changed_objects = array();
434 
435  if ($the_objects_to_be_changed && is_array($the_objects_to_be_changed) && count($the_objects_to_be_changed)) {
436  $new_shared_id = 0;
437  $langs = $this->my_server->GetFormatLangs();
438 
439  foreach ($the_objects_to_be_changed as $one_format) {
440  if (!(($one_format instanceof c_comdef_format) && $one_format->UpdateToDB())) {
441  $the_objects_to_be_changed = null;
442  $ret_data = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['format_change_fader_change_fail_text']);
443  break;
444  }
445 
446  if (!$one_format->GetSharedID()) {
447  $one_format->SetSharedID($new_shared_id);
448  }
449 
450  $saved_format_object = array (
451  'shared_id' => $one_format->GetSharedID(),
452  'lang_key' => $one_format->GetLocalLang(),
453  'lang_name' => $langs[$one_format->GetLocalLang()],
454  'key' => $one_format->GetKey(),
455  'name' => $one_format->GetLocalName(),
456  'description' => $one_format->GetLocalDescription(),
457  'type' => $one_format->GetFormatType(),
458  'worldid_mixed' => $one_format->GetWorldID()
459  );
460 
461  $new_shared_id = $saved_format_object['shared_id'];
462 
463  $the_changed_objects[$one_format->GetLocalLang()] = $saved_format_object;
464  }
465 
466  // Now, we go through the server's formats, and delete any that aren't reflected in the incoming data.
467  foreach ($langs as $lang_key => $lang_name) {
468  $server_format = $this->my_server->GetOneFormat($shared_id, $lang_key);
469 
470  if ($server_format && !$the_changed_formats[$lang_key]) {
471  $server_format->DeleteFromDB();
472  }
473  }
474  } else {
475  $ret_data = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['format_change_fader_change_fail_text']);
476  }
477 
478  header('Content-Type:application/json; charset=UTF-8');
479  if ($ret_data) {
480  echo "{'success':false,'report':'$ret_data'}";
481  } else {
482  echo "{'success':true,'report':".array2json($the_changed_objects)."}";
483  }
484  } else {
485  echo 'NOT AUTHORIZED';
486  }
487  }
488 
489  /*******************************************************************/
490  /**
491  \brief
492  */
493  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
494  public function HandleDeleteFormat( $in_format_shared_id ///< The shared ID of the formats to delete.
495  )
496  {
497  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
498  if (c_comdef_server::IsUserServerAdmin(null, true)) {
499  $ret_data = '';
500 
501  $langs = $this->my_server->GetFormatLangs();
502 
503  foreach ($langs as $lang_key => $lang_name) {
504  $server_format = $this->my_server->GetOneFormat($in_format_shared_id, $lang_key);
505 
506  if ($server_format instanceof c_comdef_format) {
507  $server_format->DeleteFromDB();
508  }
509  }
510 
511  header('Content-Type:application/json; charset=UTF-8');
512  if ($ret_data) {
513  echo "{'success':false,'report':'$ret_data'}";
514  } else {
515  echo "{'success':true,'report':$in_format_shared_id}";
516  }
517  } else {
518  echo 'NOT AUTHORIZED';
519  }
520  }
521 
522  /*******************************************************************/
523  /**
524  \brief
525  */
526  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
527  public function HandleUserCreate( $in_user_data ///< A JSON object, containing the new User data.
528  )
529  {
530  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
531  if (c_comdef_server::IsUserServerAdmin(null, true)) {
532  $json_tool = new PhpJsonXmlArrayStringInterchanger;
533 
534  $the_new_user = $json_tool->convertJsonToArray($in_user_data, true);
535 
536  if (is_array($the_new_user) && count($the_new_user)) {
537  $id = $the_new_user[0];
538  $login = $the_new_user[1];
539  $name = $the_new_user[2];
540  $description = $the_new_user[3];
541  $email = $the_new_user[4];
542  $user_level = intval($the_new_user[5]);
543  $password = trim($the_new_user[6]);
544  $user_owner = intval($the_new_user[7]);
545 
546  $user_owner_user = $this->my_server->GetUserByIDObj($user_owner);
547  if (is_null($user_owner_user) || $user_owner_user->GetUserLevel() == _USER_LEVEL_SERVER_ADMIN) {
548  $user_owner = -1;
549  }
550 
551  if (!$this->my_server->GetUserByLogin($login)) {
552  $user_to_create = new c_comdef_user(null, 0, $user_level, $email, $login, "", $this->my_server->GetLocalLang(), $name, $description, $user_owner, null);
553 
554  if ($user_to_create instanceof c_comdef_user) {
555  if ($password) {
556  $user_to_create->SetNewPassword($password);
557  }
558 
559  if ($user_to_create->UpdateToDB()) {
560  // Get whatever ID was assigned to this User.
561  $the_new_user[0] = intval($user_to_create->GetID());
562  header('Content-Type:application/json; charset=UTF-8');
563  echo "{'success':true,'user':".array2json($the_new_user)."}";
564  } else {
565  $err_string = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['user_change_fader_create_fail_text']);
566  header('Content-Type:application/json; charset=UTF-8');
567  echo "{'success':false,'report':'$err_string'}";
568  }
569  } else {
570  $err_string = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['user_change_fader_create_fail_text']);
571  header('Content-Type:application/json; charset=UTF-8');
572  echo "{'success':false,'report':'$err_string'}";
573  }
574  } else {
575  $err_string = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['user_change_fader_create_fail_already_exists']);
576  header('Content-Type:application/json; charset=UTF-8');
577  echo "{'success':false,'report':'$err_string'}";
578  }
579  } else {
580  $err_string = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['user_change_fader_create_fail_text']);
581  header('Content-Type:application/json; charset=UTF-8');
582  echo "{'success':false,'report':'$err_string'}";
583  }
584  } else {
585  echo 'NOT AUTHORIZED';
586  }
587  }
588 
589  /*******************************************************************/
590  /**
591  \brief
592  */
593  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
594  public function HandleUserChange( $in_user_data ///< A JSON object, containing the new User data.
595  )
596  {
597  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
598  $isServerAdmin = c_comdef_server::IsUserServerAdmin(null, true);
599  $isServiceBodyAdmin = c_comdef_server::IsUserServiceBodyAdmin(null, true);
600  if ($isServerAdmin || $isServiceBodyAdmin) {
601  $json_tool = new PhpJsonXmlArrayStringInterchanger;
602 
603  $the_changed_user = $json_tool->convertJsonToArray($in_user_data, true);
604 
605  if (is_array($the_changed_user) && count($the_changed_user)) {
606  $id = $the_changed_user[0];
607  $login = $the_changed_user[1];
608  $name = $the_changed_user[2];
609  $description = $the_changed_user[3];
610  $email = $the_changed_user[4];
611  $user_level = intval($the_changed_user[5]);
612  $password = trim($the_changed_user[6]);
613  $user_owner = intval($the_changed_user[7]);
614  $user_to_change = $this->my_server->GetUserByIDObj($id);
615 
616  $user_owner_user = $this->my_server->GetUserByIDObj($user_owner);
617  if (is_null($user_owner_user) || $user_owner_user->GetUserLevel() == _USER_LEVEL_SERVER_ADMIN) {
618  $user_owner = -1;
619  }
620 
621  if ($user_to_change instanceof c_comdef_user) {
622  // Don't allow service body admins to make changes to users they don't own
623  if ($isServiceBodyAdmin && $user_to_change->GetOwnerID() != c_comdef_server::GetCurrentUserObj()->GetID()) {
624  echo 'NOT AUTHORIZED';
625  return;
626  }
627 
628  $user_to_change->SetLogin($login);
629  $user_to_change->SetLocalName($name);
630  $user_to_change->SetLocalDescription($description);
631  $user_to_change->SetEmailAddress($email);
632  // Only allow server admins to set user level and user owner
633  if ($isServerAdmin) {
634  $user_to_change->SetUserLevel($user_level);
635  $user_to_change->SetOwnerID($user_owner);
636  }
637 
638  if ($password) {
639  if (!$user_to_change->SetNewPassword($password)) {
640  $err_string = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['user_change_fader_fail_cant_update_text']);
641  header('Content-Type:application/json; charset=UTF-8');
642  echo "{\"success\":false,\"report\":\"$err_string\"}";
643  return;
644  }
645  }
646 
647  if ($user_to_change->UpdateToDB()) {
648  header('Content-Type:application/json; charset=UTF-8');
649  echo '{"success":true,"user":'.array2json($the_changed_user)."}";
650  } else {
651  $err_string = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['user_change_fader_fail_cant_update_text']);
652  header('Content-Type:application/json; charset=UTF-8');
653  echo "{\"success\":false,\"report\":\"$err_string\"}";
654  }
655  } else {
656  $err_string = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['user_change_fader_fail_cant_find_sb_text']);
657  header('Content-Type:application/json; charset=UTF-8');
658  echo "{\"success\":false,\"report\":\"$err_string\"}";
659  }
660  } else {
661  $err_string = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['user_change_fader_fail_no_data_text']);
662  header('Content-Type:application/json; charset=UTF-8');
663  echo "{\"success\":false,\"report\":\"$err_string\"}";
664  }
665  } else {
666  echo 'NOT AUTHORIZED';
667  }
668  }
669 
670  /*******************************************************************/
671  /**
672  \brief
673  */
674  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
675  public function HandleDeleteUser(
676  $in_user_id, ///< The ID of the user to be deleted.
677  $in_delete_permanently = false
678  ) {
679  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
680  $err_string = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['user_change_fader_delete_fail_text']);
681  if (c_comdef_server::IsUserServerAdmin(null, true)) {
682  try {
683  $user_to_delete = $this->my_server->GetUserByIDObj($in_user_id);
684 
685  if ($user_to_delete instanceof c_comdef_user) {
686  if ($user_to_delete->DeleteFromDB()) {
687  $user_to_delete->ResetChildUsers();
688  if ($in_delete_permanently) {
689  $this->DeleteUserChanges($in_user_id);
690  }
691 
692  header('Content-Type:application/json; charset=UTF-8');
693  echo "{'success':true,'report':'$in_user_id'}";
694  } else {
695  header('Content-Type:application/json; charset=UTF-8');
696  echo "{'success':false,'report':'$ierr_string'}";
697  }
698  } else {
699  header('Content-Type:application/json; charset=UTF-8');
700  echo "{'success':false,'report':'$ierr_string'}";
701  }
702  } catch (Exception $e) {
703  header('Content-Type:application/json; charset=UTF-8');
704  echo "{'success':false,'report':'$ierr_string'}";
705  }
706  } else {
707  echo 'NOT AUTHORIZED';
708  }
709  }
710 
711  /*******************************************************************/
712  /**
713  */
714  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
715  public function DeleteUserChanges($in_user_id)
716  {
717  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
718  if (c_comdef_server::IsUserServerAdmin(null, true)) {
719  $changes = $this->my_server->GetChangesFromIDAndType('c_comdef_user', $in_user_id);
720 
721  if ($changes instanceof c_comdef_changes) {
722  $obj_array = $changes->GetChangesObjects();
723 
724  if (is_array($obj_array) && count($obj_array)) {
725  foreach ($obj_array as $change) {
726  $change->DeleteFromDB();
727  }
728  }
729  }
730  }
731  }
732 
733  /*******************************************************************/
734  /**
735  \brief This handles updating an existing Service body.
736  */
737  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
738  public function HandleServiceBodyChange( $in_service_body_data ///< A JSON object, containing the new Service Body data.
739  )
740  {
741  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
742  $json_tool = new PhpJsonXmlArrayStringInterchanger;
743 
744  $the_new_service_body = $json_tool->convertJsonToArray($in_service_body_data, true);
745 
746  if (is_array($the_new_service_body) && count($the_new_service_body)) {
747  $id = $the_new_service_body[0];
748  $parent_service_body_id = $the_new_service_body[1];
749  $name = $the_new_service_body[2];
750  $description = $the_new_service_body[3];
751  $main_user_id = $the_new_service_body[4];
752  $editor_ids = explode(',', $the_new_service_body[5]);
753  $email = $the_new_service_body[6];
754  $uri = $the_new_service_body[7];
755  $helpline = $the_new_service_body[8];
756  $type = $the_new_service_body[9];
757  $worldid = $the_new_service_body[12];
758 
759  $sb_to_change = $this->my_server->GetServiceBodyByIDObj($id);
760 
761  if ($sb_to_change instanceof c_comdef_service_body) {
762  $sb_to_change->SetOwnerID($parent_service_body_id);
763  $sb_to_change->SetLocalName($name);
764  $description = preg_replace('|[^\S]+?|', " ", $description);
765  $sb_to_change->SetLocalDescription($description);
766  $sb_to_change->SetPrincipalUserID($main_user_id);
767  $sb_to_change->SetEditors($editor_ids);
768  $sb_to_change->SetContactEmail($email);
769  $sb_to_change->SetURI($uri);
770  $sb_to_change->SetHelpline($helpline);
771  $sb_to_change->SetSBType($type);
772  $sb_to_change->SetWorldID($worldid);
773 
774  if ($sb_to_change->UpdateToDB()) {
775  header('Content-Type:application/json; charset=UTF-8');
776  echo "{'success':true,'service_body':".array2json($the_new_service_body)."}";
777  } else {
778  $err_string = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['service_body_change_fader_fail_cant_update_text']);
779  header('Content-Type:application/json; charset=UTF-8');
780  echo "{'success':false,'report':'$err_string'}";
781  }
782  } else {
783  $err_string = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['service_body_change_fader_fail_cant_find_sb_text']);
784  header('Content-Type:application/json; charset=UTF-8');
785  echo "{'success':false,'report':'$err_string'}";
786  }
787  } else {
788  $err_string = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['service_body_change_fader_fail_no_data_text']);
789  header('Content-Type:application/json; charset=UTF-8');
790  echo "{'success':false,'report':'$err_string'}";
791  }
792  }
793 
794  /*******************************************************************/
795  /**
796  \brief This handles creating a new Service body.
797  */
798  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
799  public function HandleServiceBodyCreate( $in_service_body_data ///< A JSON object, containing the new Service Body data.
800  )
801  {
802  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
803  if (c_comdef_server::IsUserServerAdmin(null, true)) {
804  $json_tool = new PhpJsonXmlArrayStringInterchanger;
805 
806  $the_new_service_body = $json_tool->convertJsonToArray($in_service_body_data, true);
807 
808  if (is_array($the_new_service_body) && count($the_new_service_body)) {
809  $id = $the_new_service_body[0];
810  $parent_service_body_id = $the_new_service_body[1];
811  $name = $the_new_service_body[2];
812  $description = $the_new_service_body[3];
813  $main_user_id = $the_new_service_body[4];
814  $editor_ids = explode(',', $the_new_service_body[5]);
815  $email = $the_new_service_body[6];
816  $uri = $the_new_service_body[7];
817  $helpline = $the_new_service_body[8];
818  $type = $the_new_service_body[9];
819  $worldid = $the_new_service_body[12];
820 
821  $sb_to_create = new c_comdef_service_body;
822 
823  if ($sb_to_create instanceof c_comdef_service_body) {
824  $sb_to_create->SetOwnerID($parent_service_body_id);
825  $sb_to_create->SetLocalName($name);
826  $sb_to_create->SetLocalDescription($description);
827  $sb_to_create->SetPrincipalUserID($main_user_id);
828  $sb_to_create->SetEditors($editor_ids);
829  $sb_to_create->SetContactEmail($email);
830  $sb_to_create->SetURI($uri);
831  $sb_to_create->SetHelpline($helpline);
832  $sb_to_create->SetSBType($type);
833  $sb_to_create->SetWorldID($worldid);
834 
835  if ($sb_to_create->UpdateToDB()) {
836  // Get whatever ID was assigned to this Service Body.
837  $the_new_service_body[0] = $sb_to_create->GetID();
838  header('Content-Type:application/json; charset=UTF-8');
839  echo "{'success':true,'service_body':".array2json($the_new_service_body)."}";
840  } else {
841  $err_string = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['service_body_change_fader_fail_cant_update_text']);
842  header('Content-Type:application/json; charset=UTF-8');
843  echo "{'success':false,'report':'$err_string'}";
844  }
845  } else {
846  $err_string = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['service_body_change_fader_fail_cant_find_sb_text']);
847  header('Content-Type:application/json; charset=UTF-8');
848  echo "{'success':false,'report':'$err_string'}";
849  }
850  } else {
851  $err_string = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['service_body_change_fader_fail_no_data_text']);
852  header('Content-Type:application/json; charset=UTF-8');
853  echo "{'success':false,'report':'$err_string'}";
854  }
855  } else {
856  echo 'NOT AUTHORIZED';
857  }
858  }
859 
860  /*******************************************************************/
861  /**
862  \brief
863  */
864  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
865  public function HandleDeleteServiceBody(
866  $in_sb_id,
867  $in_delete_permanently = false
868  ) {
869  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
870  $err_string = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['service_body_change_fader_delete_fail_text']);
871 
872  if (c_comdef_server::IsUserServerAdmin(null, true)) {
873  try {
874  $service_body = $this->my_server->GetServiceBodyByIDObj($in_sb_id);
875 
876  if ($service_body instanceof c_comdef_service_body) {
877  if ($service_body->DeleteFromDB()) {
878  if ($in_delete_permanently) {
879  $this->DeleteServiceBodyChanges($in_sb_id);
880  }
881 
882  header('Content-Type:application/json; charset=UTF-8');
883  echo "{'success':true, 'id':$in_sb_id}";
884  } else {
885  header('Content-Type:application/json; charset=UTF-8');
886  echo "{'success':false,'report':'$err_string'}";
887  }
888  } else {
889  header('Content-Type:application/json; charset=UTF-8');
890  echo "{'success':false,'report':'$err_string'}";
891  }
892  } catch (Exception $e) {
893  header('Content-Type:application/json; charset=UTF-8');
894  echo "{'success':false,'report':'$err_string'}";
895  }
896  } else {
897  echo 'NOT AUTHORIZED';
898  }
899  }
900 
901  /*******************************************************************/
902  /**
903  */
904  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
905  public function DeleteServiceBodyChanges($in_sb_id)
906  {
907  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
908  if (c_comdef_server::IsUserServerAdmin(null, true)) {
909  $changes = $this->my_server->GetChangesFromIDAndType('c_comdef_service_body', $in_sb_id);
910 
911  if ($changes instanceof c_comdef_changes) {
912  $obj_array = $changes->GetChangesObjects();
913 
914  if (is_array($obj_array) && count($obj_array)) {
915  foreach ($obj_array as $change) {
916  $change->DeleteFromDB();
917  }
918  }
919  }
920  }
921  }
922 
923  /*******************************************************************/
924  /**
925  \brief
926  */
927  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
928  public function GetMeetingHistory($in_meeting_id)
929  {
930  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
931  $ret = '[';
932  $changes = $this->my_server->GetChangesFromIDAndType('c_comdef_meeting', $in_meeting_id);
933 
934  if ($changes instanceof c_comdef_changes) {
935  $obj_array = $changes->GetChangesObjects();
936 
937  if (is_array($obj_array) && count($obj_array)) {
938  $first = true;
939 
940  foreach ($obj_array as $change) {
941  if (!$first) {
942  $ret .= ',';
943  } else {
944  $first = false;
945  }
946 
947  $ret .= '{';
948  $change_id = $change->GetID();
949  $user_id = $change->GetUserID();
950  if ($user_id) {
951  $user_object = $this->my_server->GetUserByIDObj($change->GetUserID());
952  if ($user_object) {
953  $user_name = json_prepare($user_object->GetLocalName());
954  }
955  }
956  $change_description = json_prepare($change->DetailedChangeDescription());
957  $change_date = json_prepare(date('g:i A, F j Y', $change->GetChangeDate()));
958 
959  $ret .= '"id":'.$change_id.',';
960  $ret .= '"user":"'.$user_name.'",';
961  $ret .= '"description":["'.implode('","', str_replace('&amp;', '&', $change_description['details'])).'"],';
962  $ret .= '"date":"'.$change_date.'"';
963 
964  $ret .= '}';
965  }
966  }
967  }
968 
969  $ret .= ']';
970 
971  return $ret;
972  }
973 
974  /*******************************************************************/
975  /**
976  \brief
977  */
978  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
979  public function HandleDeleteMeeting(
980  $in_meeting_id
981  ) {
982  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
983  try {
984  $meeting = $this->my_server->GetOneMeeting($in_meeting_id);
985 
986  if ($meeting instanceof c_comdef_meeting) {
987  if ($meeting->UserCanEdit()) {
988  if ($meeting->DeleteFromDB()) {
989  header('Content-Type:application/json; charset=UTF-8');
990  echo "{'success':true,'report':'$in_meeting_id'}";
991  } else {
992  header('Content-Type:application/json; charset=UTF-8');
993  echo "{'success':false,'report':'$in_meeting_id'}";
994  }
995  } else {
996  header('Content-Type:application/json; charset=UTF-8');
997  echo "{'success':false,'report':'$in_meeting_id'}";
998  }
999  } else {
1000  header('Content-Type:application/json; charset=UTF-8');
1001  echo "{'success':false,'report':'$in_meeting_id'}";
1002  }
1003  } catch (Exception $e) {
1004  header('Content-Type:application/json; charset=UTF-8');
1005  echo "{'success':false,'report':'$in_meeting_id'}";
1006  }
1007  }
1008 
1009  /*******************************************************************/
1010  /**
1011  */
1012  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
1013  public function DeleteMeetingChanges($in_meeting_id)
1014  {
1015  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
1016  if (c_comdef_server::IsUserServerAdmin(null, true)) {
1017  $changes = $this->my_server->GetChangesFromIDAndType('c_comdef_meeting', $in_meeting_id);
1018 
1019  if ($changes instanceof c_comdef_changes) {
1020  $obj_array = $changes->GetChangesObjects();
1021 
1022  if (is_array($obj_array) && count($obj_array)) {
1023  foreach ($obj_array as $change) {
1024  $change->DeleteFromDB();
1025  }
1026  }
1027  }
1028  }
1029  }
1030 
1031  /*******************************************************************/
1032  /**
1033  \brief This handles updating an existing meeting, or adding a new one.
1034  */
1035  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
1036  public function HandleMeetingUpdate( $in_meeting_data ///< A JSON object, containing the new meeting data.
1037  )
1038  {
1039  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
1040  $json_tool = new PhpJsonXmlArrayStringInterchanger;
1041 
1042  $the_new_meeting = $json_tool->convertJsonToArray($in_meeting_data, true);
1043 
1044  if (is_array($the_new_meeting) && count($the_new_meeting)) {
1046  try {
1047  $this->SetMeetingDataValues($the_new_meeting);
1048  } catch (Exception $e) {
1049  c_comdef_dbsingleton::rollback();
1050  throw $e;
1051  }
1053  }
1054  }
1055 
1056  /*******************************************************************/
1057  /**
1058  \brief
1059  */
1060  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
1061  public function SetMeetingDataValues($in_meeting_data, $print_result = true)
1062  {
1063  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
1064  try {
1065  if ($in_meeting_data['id_bigint']) {
1066  $meeting = $this->my_server->GetOneMeeting($in_meeting_data['id_bigint']);
1067  } else {
1068  $data = array ( 'service_body_bigint' => intval($in_meeting_data['service_body_bigint']),
1069  'weekday_tinyint' => intval($in_meeting_data['weekday_tinyint']),
1070  'start_time' => $in_meeting_data['start_time'],
1071  'lang_enum' => (isset($in_meeting_data['lang_enum']) && $in_meeting_data['lang_enum']) ? $in_meeting_data['lang_enum'] : $this->my_server->GetLocalLang()
1072  );
1073  $meeting = new c_comdef_meeting($this->my_server, $data);
1074  }
1075 
1076  if ($meeting instanceof c_comdef_meeting) {
1077  // Security precaution: We check the session to make sure that the user is authorized for this meeting.
1078  if ($meeting->UserCanEdit()) {
1079  $result_data = array ( 'meeting_id' => $in_meeting_data['id_bigint'] );
1080  $data =& $meeting->GetMeetingData();
1081 
1082  // We prepare the "template" array. These are the data values for meeting 0 in the two tables.
1083  // We will use them to provide default visibility values. Only the server admin can override these.
1084  // This is where we get a list of the available "optional" fields to put in a popup for adding a new one.
1085  $template_data = c_comdef_meeting::GetDataTableTemplate();
1086  $template_longdata = c_comdef_meeting::GetLongDataTableTemplate();
1087 
1088  // We merge the two tables (data and longdata).
1089  if (is_array($template_data) && count($template_data) && is_array($template_longdata) && count($template_longdata)) {
1090  $template_data = array_merge($template_data, $template_longdata);
1091  }
1092 
1093  foreach ($in_meeting_data as $key => $value) {
1094  if ($key == 'formats') {
1095  continue;
1096  }
1097 
1098  if ($key == 'format_shared_id_list') {
1099  $vals = array();
1100  $value = explode(",", $value);
1101  $lang = $this->my_server->GetLocalLang();
1102  foreach ($value as $sharedID) {
1103  $sharedID = intval($sharedID);
1104  $object = c_comdef_server::GetServer()->GetFormatsObj()->GetFormatBySharedIDCodeAndLanguage($sharedID, $lang);
1105  if ($object) {
1106  $vals[$sharedID] = $object;
1107  }
1108  }
1109  uksort($vals, array ( 'c_comdef_meeting','format_sorter_simple' ));
1110  $value = $vals;
1111  $key = 'formats';
1112  }
1113 
1114  switch ($key) {
1115  case 'zoom':
1116  case 'distance_in_km': // These are ignored.
1117  case 'distance_in_miles':
1118  break;
1119 
1120  // These are the "fixed" or "core" data values.
1121  case 'worldid_mixed':
1122  case 'start_time':
1123  case 'lang_enum':
1124  case 'duration_time':
1125  case 'time_zone':
1126  case 'formats':
1127  $data[$key] = $value;
1128  break;
1129 
1130  case 'longitude':
1131  case 'latitude':
1132  $data[$key] = floatval($value);
1133  break;
1134 
1135  case 'id_bigint':
1136  case 'service_body_bigint':
1137  case 'weekday_tinyint':
1138  $data[$key] = intval($value);
1139  break;
1140 
1141  case 'email_contact':
1142  $value = trim($value);
1143  if ($value) {
1144  if (c_comdef_vet_email_address($value)) {
1145  $data[$key] = $value;
1146  } else {
1147  $err_string = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['email_format_bad']);
1148  header('Content-Type:application/json; charset=UTF-8');
1149  die("{'error':true,'type':'email_format_bad','report':'$err_string','id':'".$in_meeting_data['id_bigint']."'}");
1150  }
1151  } else {
1152  $data[$key] = $value;
1153  }
1154  break;
1155 
1156  // We only accept a 1 or a 0.
1157  case 'published':
1158  // Meeting list editors can't publish meetings.
1159  if (c_comdef_server::GetCurrentUserObj(true)->GetUserLevel() != _USER_LEVEL_EDITOR) {
1160  $data[$key] = $value ? 1 : 0;
1161  }
1162  break;
1163 
1164  case 'root_server_uri':
1165  break; // This should just be a calculated field, so don't save it
1166 
1167  // These are the various "optional" fields.
1168  default:
1169  if (isset($data[$key])) {
1170  $data[$key]['meetingid_bigint'] = $in_meeting_data['id_bigint'];
1171  $data[$key]['value'] = $value;
1172  } else {
1173  $template_field_prompt = array_key_exists($key, $template_data) ? $template_data[$key]['field_prompt'] : null;
1174  $template_visibility = array_key_exists($key, $template_data) ? $template_data[$key]['visibility'] : null;
1175  $result_data['new_data']['key'] = $key;
1176  $result_data['new_data']['field_prompt'] = $template_field_prompt;
1177  $result_data['new_data']['value'] = $value;
1178  $meeting->AddDataField($key, $template_field_prompt, $value, null, intval($template_visibility));
1179  }
1180  break;
1181  }
1182  }
1183  if ($meeting->UpdateToDB()) {
1184  $used_formats = array();
1185  $result = $this->TranslateToJSON($this->GetSearchResults(array ( 'meeting_ids' => array ( $meeting->GetID() ) ), $used_formats));
1186  if ($print_result) {
1187  header('Content-Type:application/json; charset=UTF-8');
1188  echo $result;
1189  } else {
1190  return $result;
1191  }
1192  } else {
1193  $in_meeting_data['id_bigint'] = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['edit_Meeting_meeting_id']).$in_meeting_data['id_bigint'];
1194  $err_string = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['edit_Meeting_auth_failure']);
1195  $result = "{'error':true,'type':'auth_failure','report':'$err_string','info':'".$in_meeting_data['id_bigint']."'}";
1196  if ($print_result) {
1197  header('Content-Type:application/json; charset=UTF-8');
1198  echo $result;
1199  } else {
1200  return $result;
1201  }
1202  }
1203  } else {
1204  $in_meeting_data['id_bigint'] = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['edit_Meeting_meeting_id']).$in_meeting_data['id_bigint'];
1205  $err_string = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['edit_Meeting_auth_failure']);
1206  $result = "{'error':true,'type':'auth_failure','report':'$err_string','info':'".$in_meeting_data['id_bigint']."'}";
1207  if ($print_result) {
1208  header('Content-Type:application/json; charset=UTF-8');
1209  echo $result;
1210  } else {
1211  return $result;
1212  }
1213  }
1214  } else {
1215  $in_meeting_data['id_bigint'] = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['edit_Meeting_meeting_id']).$in_meeting_data['id_bigint'];
1216  $err_string = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['edit_Meeting_object_not_found']);
1217  $result = "{'error':true,'type':'object_not_found','report':'$err_string','info':'".$in_meeting_data['id_bigint']."'}";
1218  if ($print_result) {
1219  header('Content-Type:application/json; charset=UTF-8');
1220  echo $result;
1221  } else {
1222  return $result;
1223  }
1224  }
1225  } catch (Exception $e) {
1226  $in_meeting_data['id_bigint'] = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['edit_Meeting_meeting_id']).$in_meeting_data['id_bigint'];
1227  $err_string = json_prepare($this->my_localized_strings['comdef_server_admin_strings']['edit_Meeting_object_not_changed']);
1228  $result = "{'error':true,'type':'object_not_changed','report':'$err_string','info':'".$in_meeting_data['id_bigint']."'}";
1229  if ($print_result) {
1230  header('Content-Type:application/json; charset=UTF-8');
1231  echo $result;
1232  } else {
1233  return $result;
1234  }
1235  }
1236  }
1237 
1238  /*******************************************************************/
1239  /**
1240  \brief This returns the search results, in whatever form was requested.
1241 
1242  \returns CSV data, with the first row a key header.
1243  */
1244  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
1245  public function GetSearchResults(
1246  $in_http_vars, ///< The HTTP GET and POST parameters.
1247  &$formats_ar ///< This will return the formats used in this search.
1248  ) {
1249  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
1250  if (!( isset($in_http_vars['geo_width']) && $in_http_vars['geo_width'] ) && isset($in_http_vars['bmlt_search_type']) && ($in_http_vars['bmlt_search_type'] == 'advanced') && isset($in_http_vars['advanced_radius']) && isset($in_http_vars['advanced_mapmode']) && $in_http_vars['advanced_mapmode'] && ( floatval($in_http_vars['advanced_radius'] != 0.0) ) && isset($in_http_vars['lat_val']) && isset($in_http_vars['long_val']) && ( (floatval($in_http_vars['lat_val']) != 0.0) || (floatval($in_http_vars['long_val']) != 0.0) )) {
1251  $in_http_vars['geo_width'] = $in_http_vars['advanced_radius'];
1252  } elseif (!( isset($in_http_vars['geo_width']) && $in_http_vars['geo_width'] ) && isset($in_http_vars['bmlt_search_type']) && ($in_http_vars['bmlt_search_type'] == 'advanced')) {
1253  $in_http_vars['lat_val'] = null;
1254  $in_http_vars['long_val'] = null;
1255  } elseif (!isset($in_http_vars['geo_loc']) || $in_http_vars['geo_loc'] != 'yes') {
1256  if (!isset($in_http_vars['geo_width'])) {
1257  $in_http_vars['geo_width'] = 0;
1258  }
1259  }
1260 
1261  $geocode_results = null;
1262  $ignore_me = null;
1263  $meeting_objects = array();
1264 
1265  $result = DisplaySearchResultsCSV($in_http_vars, $ignore_me, $geocode_results, $meeting_objects, true, true);
1266 
1267  if (isset($meeting_objects) && is_array($meeting_objects) && count($meeting_objects) && isset($formats_ar) && is_array($formats_ar)) {
1268  foreach ($meeting_objects as $one_meeting) {
1269  $formats = $one_meeting->GetMeetingDataValue('formats');
1270 
1271  foreach ($formats as $format) {
1272  if ($format && ($format instanceof c_comdef_format)) {
1273  $format_shared_id = $format->GetSharedID();
1274  $formats_ar[$format_shared_id] = $format;
1275  }
1276  }
1277  }
1278  }
1279 
1280  if (isset($in_http_vars['data_field_key']) && $in_http_vars['data_field_key']) {
1281  // At this point, we have everything in a CSV. We separate out just the field we want.
1282  $temp_keyed_array = array();
1283  $result = explode("\n", $result);
1284  $keys = array_shift($result);
1285  $keys = explode("\",\"", trim($keys, '"'));
1286  $the_keys = explode(',', $in_http_vars['data_field_key']);
1287 
1288  $result2 = array();
1289  foreach ($result as $row) {
1290  if ($row) {
1291  $index = 0;
1292  $row = explode('","', trim($row, '",'));
1293  $row_columns = array();
1294  foreach ($row as $column) {
1295  if (isset($column)) {
1296  if (in_array($keys[$index++], $the_keys)) {
1297  array_push($row_columns, $column);
1298  }
1299  }
1300  }
1301  $result2[$row[0]] = '"'.implode('","', $row_columns).'"';
1302  }
1303  }
1304 
1305  $the_keys = array_intersect($keys, $the_keys);
1306  $result = '"'.implode('","', $the_keys)."\"\n".implode("\n", $result2);
1307  }
1308 
1309  return $result;
1310  }
1311 
1312  /*******************************************************************/
1313  /**
1314  \brief Translates CSV to JSON.
1315 
1316  \returns a JSON string, with all the data in the CSV.
1317  */
1318  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
1319  public function TranslateToJSON( $in_csv_data ///< An array of CSV data, with the first element being the field names.
1320  )
1321  {
1322  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
1323  $temp_keyed_array = array();
1324  $in_csv_data = explode("\n", $in_csv_data);
1325  $keys = array_shift($in_csv_data);
1326  $keys = explode("\",\"", trim($keys, '"'));
1327 
1328  foreach ($in_csv_data as $row) {
1329  if ($row) {
1330  $line = null;
1331  $index = 0;
1332  $row = trim($row);
1333  if (substr($row, 0, 1) == '"') { // Strip first double quote
1334  $row = substr($row, 1, strlen($row) - 1);
1335  }
1336  if (substr($row, strlen($row) - 1, 1) == ',') { // Strip last comma, just in case
1337  $row = substr($row, 0, strlen($row) - 1);
1338  }
1339  if (substr($row, strlen($row) - 1, 1) == '"') { // Strip last double quote
1340  $row = substr($row, 0, strlen($row) - 1);
1341  }
1342  $row = explode('","', $row);
1343  foreach ($row as $column) {
1344  if (isset($column)) {
1345  $line[$keys[$index++]] = $column;
1346  }
1347  }
1348  array_push($temp_keyed_array, $line);
1349  }
1350  }
1351 
1352  $out_json_data = array2json($temp_keyed_array);
1353 
1354  return $out_json_data;
1355  }
1356 }
1357 
1359 
1360 $ret = 'ERROR';
1361 
1363  $ret = $handler->parse_ajax_call();
1364 }
1365 
1366 echo $ret;
static GetLocalStrings($in_lang_enum=null)
This gets the appropriate language files, and puts all the the strings into an associative array...
$uri
Definition: index.php:25
static GetMeetingsForAServiceBody($in_sb_id)
Returns a c_comdef_meetings_object, containing all the meetings directly "owned" by the Service Body ...
A Class for Service Body Objects.
A class to hold a single meeting object.
TranslateToJSON($in_csv_data)
Translates CSV to JSON.
This class handles BMLT users. One instance is created for each user on the server.
HandleDeleteUser($in_user_id, $in_delete_permanently=false)
static GetLongDataTableTemplate($in_lang_enum=null)
Returns an array that provides a template for the long data table values (the optional/additional val...
$my_user
This holds the instance of the logged-in user.
c_comdef_vet_email_address($in_address)
This function vets the email address for proper form.
SetOwnerID($in_sb_owner)
Accessor - Sets the ID of the &#39;owner&#39; of this object.
const _USER_LEVEL_DISABLED
const _USER_LEVEL_SERVER_ADMIN
A Class for Format Codes.
HandleServiceBodyChange($in_service_body_data)
This handles updating an existing Service body.
global $http_vars
Definition: index.php:21
GetSearchResults($in_http_vars, &$formats_ar=null, &$meanLocationData=null)
This returns the search results, in whatever form was requested.
Definition: csv.php:752
$my_localized_strings
This will contain the localized strings and whatnot for display.
static IsUserServiceBodyAdmin($in_user_obj=null, $in_is_ajax=false)
Find out if the user is a service body admin.
HandleMeetingUpdate($in_meeting_data)
This handles updating an existing meeting, or adding a new one.
const _USER_LEVEL_EDITOR
array2json($arr)
Encodes a given associative array into a JSON object string.
Definition: Array2Json.php:41
A class to hold a collection of c_comdef_change objects.
$my_http_vars
Contains the HTTP vars sent in.
DisplaySearchResultsCSV($in_http_vars, &$return_array=null, &$return_geocode=null, &$return_results=null, $in_supress_hidden_concat=false, $in_editor_only=false)
This function does a search, then builds a CSV result, with each row being a meeting. The first row is a row of keys.
static MakeServer()
This is the factory for the server instantiation. It makes sure that only one instance exists...
This class is the main server class. It instantiates a PDO database object, and is the starting point...
static GetDataTableTemplate()
Returns an array that provides a template for the data table values (the optional/additional values)...
HandleServiceBodyCreate($in_service_body_data)
This handles creating a new Service body.
defined('BMLT_EXEC') or define('BMLT_EXEC'
Definition: index.php:3
TranslateToJSON($in_csv_data)
Translates CSV to JSON.
Definition: csv.php:1494
static GetCurrentUserObj($in_is_ajax=false)
Get the current logged-in user, as a c_comdef_user instance.
SetNewPassword($in_password_unencrypted_string)
Accessor - Sets the password, encrypting it.
HandleDeleteServiceBody($in_sb_id, $in_delete_permanently=false)
static IsUserServerAdmin($in_user_obj=null, $in_is_ajax=false)
Find out if the user is a server admin.
SetMeetingDataValues($in_meeting_data, $print_result=true)
static GetUserServiceBodies($in_user_id=null)
Return all the Service Bodies this user is authorized with.
json_prepare($data, $escapeSpecialChars=false)
This function accepts an array of data (or a single element), and "cleans it up" in preparation for u...
GetSearchResults($in_http_vars, &$formats_ar)
This returns the search results, in whatever form was requested.