PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/interfaces/admin/classes/AdminHelper.php

https://gitlab.com/x33n/platform
PHP | 1217 lines | 994 code | 70 blank | 153 comment | 173 complexity | de9029a51e4c5bac17dc7d55178a3524 MD5 | raw file
  1. <?php
  2. /**
  3. * The AdminHelper class provides a single location for various formatting and
  4. * quick processing methods needed throughout the admin
  5. *
  6. * Most functions that are simple/static framework wrappers or data formatting should go here
  7. *
  8. * @package admin.org.cashmusic
  9. * @author CASH Music
  10. * @link http://cashmusic.org/
  11. *
  12. * Copyright (c) 2012, CASH Music
  13. * Licensed under the Affero General Public License version 3.
  14. * See http://www.gnu.org/licenses/agpl-3.0.html
  15. *
  16. */abstract class AdminHelper {
  17. public static function doLogin($email_address,$password,$require_admin=true) {
  18. global $admin_primary_cash_request;
  19. $admin_primary_cash_request->processRequest(
  20. array(
  21. 'cash_request_type' => 'system',
  22. 'cash_action' => 'validatelogin',
  23. 'address' => $email_address,
  24. 'password' => $password,
  25. 'require_admin' => $require_admin
  26. )
  27. );
  28. return $admin_primary_cash_request->response['payload'];
  29. }
  30. /**********************************************
  31. *
  32. * PAGE/UI RENDERING DETAILS
  33. *
  34. *********************************************/
  35. public static function getPageMenuDetails() {
  36. $pages_array = json_decode(file_get_contents(dirname(__FILE__).'/../components/interface/en/menu.json'),true);
  37. // remove non-multi links
  38. $platform_type = CASHSystem::getSystemSettings('instancetype');
  39. if ($platform_type == 'multi') {
  40. unset($pages_array['settings/update'],$pages_array['people/contacts']);
  41. }
  42. // make an array for return
  43. $return_array = array(
  44. 'page_title' => 'CASH Music',
  45. 'tagline' => null,
  46. 'section_menu' => '',
  47. 'link_text' => null
  48. );
  49. // generate submenu markup
  50. $current_endpoint = '';
  51. $previous_endpoint = '';
  52. $menustr = '';
  53. foreach ($pages_array as $page_endpoint => $page) {
  54. $exploded = explode('/',$page_endpoint);
  55. $current_endpoint = $exploded[0];
  56. if ($current_endpoint !== $previous_endpoint) {
  57. if ($previous_endpoint !== '') {
  58. $menustr .= '</ul>';
  59. $return_array[$previous_endpoint . '_section_menu'] = $menustr;
  60. }
  61. $menustr = '<ul>';
  62. $previous_endpoint = $current_endpoint;
  63. }
  64. $menulevel = substr_count($page_endpoint, '/');
  65. if ($menulevel == 1 && !isset($page['hide'])) { // only show top-level menu items
  66. if (!isset($page['add_class'])) {
  67. $page['add_class'] = '';
  68. }
  69. $menustr .= "<li><a title=\"{$page['page_name']}\" class=\"{$page['add_class']}\" href=\"" . ADMIN_WWW_BASE_PATH . "/$page_endpoint/\"><span>{$page['page_name']}</span><div class=\"icon icon-{$page['menu_icon']}\"></div><!--icon--></a></li>";
  70. }
  71. }
  72. // find the right page title
  73. $endpoint = str_replace('_','/',BASE_PAGENAME);
  74. $endpoint_parts = explode('/',$endpoint);
  75. if (isset($pages_array[$endpoint])) {
  76. $current_title = '';
  77. $current_title .= $pages_array[$endpoint]['page_name'];
  78. $return_array['page_title'] = $current_title;
  79. if (isset($pages_array[$endpoint]['tagline'])) {
  80. $return_array['tagline'] = $pages_array[$endpoint]['tagline'];
  81. }
  82. }
  83. // set link text for the main template
  84. $return_array['link_text'] = array(
  85. 'link_main_page' => $pages_array['mainpage']['page_name'],
  86. 'link_menu_assets' => $pages_array['assets']['page_name'],
  87. 'link_menu_people' => $pages_array['people']['page_name'],
  88. 'link_menu_commerce' => $pages_array['commerce']['page_name'],
  89. 'link_menu_calendar' => $pages_array['calendar']['page_name'],
  90. 'link_menu_elements' => $pages_array['elements']['page_name'],
  91. 'link_menu_help' => $pages_array['help']['page_name'],
  92. 'link_youraccount' => $pages_array['account']['page_name'],
  93. 'link_settings' => $pages_array['settings']['page_name'],
  94. 'link_settings_connections' => $pages_array['settings/connections']['page_name']
  95. );
  96. return $return_array;
  97. }
  98. public static function getUiText() {
  99. $text_array = json_decode(file_get_contents(dirname(__FILE__).'/../components/interface/en/interaction.json'),true);
  100. return $text_array;
  101. }
  102. public static function getPageComponents() {
  103. if (file_exists(dirname(__FILE__).'/../components/text/en/pages/' . BASE_PAGENAME . '.json')) {
  104. $components_array = json_decode(file_get_contents(dirname(__FILE__).'/../components/text/en/pages/' . BASE_PAGENAME . '.json'),true);
  105. } else {
  106. $components_array = json_decode(file_get_contents(dirname(__FILE__).'/../components/text/en/pages/default.json'),true);
  107. }
  108. return $components_array;
  109. }
  110. /**********************************************
  111. *
  112. * CONNECTION DETAILS
  113. *
  114. *********************************************/
  115. /**
  116. * Finds settings matching a specified scope and echoes them out formatted
  117. * for a dropdown box in a form
  118. *
  119. */public static function echoConnectionsOptions($scope,$selected=false,$return=false) {
  120. $applicable_settings_array = AdminHelper::getConnectionsByScope($scope);
  121. $all_connections = '<option value="0">None</option>';
  122. // echo out the proper dropdown bits
  123. if ($applicable_settings_array) {
  124. $settings_count = 1;
  125. foreach ($applicable_settings_array as $setting) {
  126. $echo_selected = '';
  127. if ($setting['id'] == $selected) { $echo_selected = ' selected="selected"'; }
  128. $all_connections .= '<option value="' . $setting['id'] . '"' . $echo_selected . '>' . $setting['name'] . '</option>';
  129. }
  130. if ($return) {
  131. return $all_connections;
  132. } else {
  133. echo $all_connections;
  134. }
  135. }
  136. }
  137. //get connections scope
  138. public static function getConnectionsByScope($scope){
  139. // get system settings:
  140. $page_data_object = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user'));
  141. $applicable_settings_array = $page_data_object->getConnectionsByScope($scope);
  142. return $applicable_settings_array;
  143. }
  144. /**
  145. * Returns the name given to a specific Connection
  146. *
  147. */public static function getConnectionName($connection_id) {
  148. $page_data_object = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user'));
  149. $connection_name = false;
  150. $connection_details = $page_data_object->getConnectionDetails($connection_id);
  151. if ($connection_details) {
  152. $connection_name = $connection_details['name'];
  153. }
  154. return $connection_name;
  155. }
  156. /**********************************************
  157. *
  158. * ELEMENT DETAILS
  159. *
  160. *********************************************/
  161. public static function getElementAppJSON($element_type) {
  162. $element_dirname = CASH_PLATFORM_ROOT.'/elements/' . $element_type;
  163. if (file_exists($element_dirname . '/app.json')) {
  164. $app_json = json_decode(file_get_contents($element_dirname . '/app.json'),true);
  165. return $app_json;
  166. } else {
  167. return false;
  168. }
  169. }
  170. public static function getElementTemplate($element_type) {
  171. $app_json = AdminHelper::getElementAppJSON($element_type);
  172. if ($app_json) {
  173. // count sections
  174. $sections_required = array();
  175. $sections_optional = array();
  176. foreach ($app_json['options'] as $section_name => $details) {
  177. foreach ($details['data'] as $data => $values) {
  178. if (isset($values['required'])) {
  179. if ($values['required']) {
  180. $sections_required[$section_name] = $details;
  181. break;
  182. }
  183. }
  184. }
  185. if (!isset($sections_required[$section_name])) {
  186. $sections_optional[$section_name] = $details;
  187. }
  188. }
  189. $all_sections = array_merge($sections_required,$sections_optional);
  190. $total_sections = count($sections_required);
  191. $template = '<div class="gallery elementinstructions"><h5>Learn more:</h5>' .
  192. '<p class="big">{{details_longdescription}}</p><p>{{{details_instructions}}}</p></div>' .
  193. '<div class="elementform"><form method="post" action="{{www_path}}/elements/{{#element_id}}edit/{{element_id}}{{/element_id}}{{^element_id}}add/' . $element_type . '{{/element_id}}" class="multipart" data-parts="' . $total_sections . '">' .
  194. '<input type="hidden" name="{{form_state_action}}" value="makeitso">' .
  195. '{{#element_id}}<input type="hidden" name="element_id" value="{{element_id}}" />{{/element_id}}' .
  196. '<input type="hidden" name="element_type" value="' . $element_type . '" />' .
  197. '<input type="hidden" name="in_campaign" id="in_campaign" value="" />' .
  198. '<div class="section basic-information" data-section-name="Element name">' .
  199. '<div class="pure-u-1"><i data-tooltip="Give the element a name for your own reference." class="tooltip icon icon-learn"></i><label for="element_name">Element name</label></div>' .
  200. '<input type="text" id="element_name" name="element_name" value="{{#element_name}}{{element_name}}{{/element_name}}"{{^element_name}} placeholder="Name your element"{{/element_name}} class="required" />' .
  201. '</div>';
  202. $current_section = 1;
  203. foreach ($all_sections as $section_name => $details) {
  204. $template .= '<div class=" section part-' . $current_section . '" data-section-name="' . $details['group_label']['en'] . '">' .
  205. '<h5 class="section-header">' . $details['group_label']['en'] . '</h5>' .
  206. '<i data-tooltip="' . $details['description']['en'] .'" class="tooltip icon icon-learn"></i>' .
  207. '<div class="pure-u-1">';
  208. $current_data = 0;
  209. $current_count = 0;
  210. $total_count = count($details);
  211. $data_keys = array_keys($details['data']);
  212. foreach ($details['data'] as $data => $values) {
  213. $current_count++;
  214. $nextnotsmall = true;
  215. if (isset($data_keys[$current_data + 1])) {
  216. if ($details['data'][$data_keys[$current_data + 1]]['displaysize'] !== 'small') {
  217. $nextnotsmall = true;
  218. } else {
  219. $nextnotsmall = false;
  220. }
  221. }
  222. if ($current_count == 4 ||
  223. $current_data == ($total_count) ||
  224. $values['displaysize'] !== 'small' ||
  225. $nextnotsmall
  226. ) {
  227. switch ($current_count) {
  228. case 4:
  229. $column_width_text = "pure-u-1 pure-u-md-1-2";
  230. break;
  231. case 3:
  232. $column_width_text = "pure-u-1 pure-u-md-1-3";
  233. break;
  234. case 2:
  235. $column_width_text = "pure-u-1 pure-u-md-1-2";
  236. break;
  237. case 1:
  238. $column_width_text = "pure-u-1";
  239. break;
  240. }
  241. // single small element — make sure it's not full width
  242. if ($values['displaysize'] == 'small' && $current_count == 1) {
  243. $column_width_text = "pure-u-1 pure-u-md-1-3";
  244. }
  245. for ($i=1; $i < $current_count+1; $i++) {
  246. $template .= '<div class="' . $column_width_text . '">' .
  247. // contents
  248. AdminHelper::drawInput(
  249. $data_keys[$current_data - ($current_count - $i)],
  250. $details['data'][$data_keys[$current_data - ($current_count - $i)]]
  251. ) .
  252. '</div>';
  253. }
  254. // single small element — make sure it's not full width
  255. if ($values['displaysize'] == 'small' && $current_count == 1) {
  256. $template .= '<div class="pure-u-1 pure-u-md-1-3"></div><div class="pure-u-1 pure-u-md-1-3"></div>';
  257. }
  258. if ($current_data !== ($total_count - 1)) {
  259. $template .= '</div><div class="pure-u-1">';
  260. }
  261. $current_count = 0;
  262. }
  263. $current_data++;
  264. }
  265. $template .= '</div></div>';
  266. $current_section++;
  267. }
  268. $template .= '<br /><input class="button" type="submit" value="{{element_button_text}}" /></form></div>';
  269. return $template;
  270. } else {
  271. return false;
  272. }
  273. }
  274. public static function drawInput($input_name,$input_data) {
  275. // label (for everything except checkboxes)
  276. if ($input_data['type'] !== 'boolean') {
  277. $return_str = '<label for="' . $input_name . '">' . $input_data['label']['en'] . '</label>';
  278. }
  279. /*
  280. start outputting markup depending on type
  281. */
  282. if ($input_data['type'] == 'text' || $input_data['type'] == 'number') {
  283. if ($input_data['type'] == 'text' && $input_data['displaysize'] == 'large') {
  284. $return_str .= '<textarea id="' . $input_name . '" name="' . $input_name . '" class="';
  285. } else {
  286. $return_str .= '<input type="text" id="' . $input_name . '" name="' . $input_name . '" value="{{#options_' . $input_name .
  287. '}}{{options_' . $input_name . '}}{{/options_' . $input_name . '}}{{^options_' . $input_name . '}}{{element_copy_' . $input_name . '}}{{/options_' . $input_name . '}}" class="';
  288. }
  289. }
  290. if ($input_data['type'] == 'select') {
  291. $return_str .= '<select id="' . $input_name . '" name="' . $input_name . '">';
  292. }
  293. if ($input_data['type'] == 'boolean') {
  294. $return_str = '<label class="checkbox" for="' . $input_name . '"><input type="checkbox" class="checkorradio" id="' . $input_name . '" name="' . $input_name . '"';
  295. }
  296. /*
  297. declare any classes that need declaring (form validation or special functionality)
  298. */
  299. if (isset($input_data['required'])) {
  300. if ($input_data['required']) {
  301. $return_str .= ' required';
  302. }
  303. }
  304. if ($input_data['type'] == 'number') {
  305. $return_str .= ' number';
  306. }
  307. /*
  308. close out markup
  309. */
  310. if ($input_data['type'] == 'text' || $input_data['type'] == 'number') {
  311. if ($input_data['type'] == 'text' && $input_data['displaysize'] == 'large') {
  312. $return_str .= '">{{#options_' . $input_name .
  313. '}}{{options_' . $input_name . '}}{{/options_' . $input_name . '}}{{^options_' . $input_name . '}}{{element_copy_' . $input_name . '}}{{/options_' . $input_name . '}}</textarea>';
  314. } else {
  315. if (isset($input_data['placeholder'])) {
  316. $return_str .= ' placeholder="' . $input_data['placeholder']['en'] . '"';
  317. }
  318. $return_str .= '" />';
  319. }
  320. }
  321. if ($input_data['type'] == 'select') {
  322. $return_str .= '{{{options_' . $input_name . '}}}</select>';
  323. }
  324. if ($input_data['type'] == 'boolean') {
  325. $return_str .= '{{#options_' . $input_name . '}} checked="checked"{{/options_' . $input_name . '}} /> ' .
  326. $input_data['label']['en'] . '</label>';
  327. }
  328. return $return_str;
  329. }
  330. public static function elementFormSubmitted($post_data) {
  331. if (isset($post_data['doelementadd']) || isset($post_data['doelementedit'])) {
  332. return true;
  333. } else {
  334. return false;
  335. }
  336. }
  337. public static function handleElementFormPOST($post_data,&$cash_admin) {
  338. global $admin_primary_cash_request;
  339. if (AdminHelper::elementFormSubmitted($post_data)) {
  340. // first create the options array
  341. $options_array = array();
  342. // now populate it from the POST data, fixing booleans
  343. $app_json = AdminHelper::getElementAppJSON($post_data['element_type']);
  344. if ($app_json) {
  345. foreach ($app_json['options'] as $section_name => $details) {
  346. foreach ($details['data'] as $data => $values) {
  347. if ($values['type'] == 'boolean') {
  348. if (isset($post_data[$data])) {
  349. $options_array[$data] = 1;
  350. } else {
  351. $options_array[$data] = 0;
  352. }
  353. } else {
  354. $options_array[$data] = $post_data[$data];
  355. }
  356. }
  357. }
  358. }
  359. if (isset($post_data['doelementadd'])) {
  360. // Adding a new element:
  361. $cash_admin->setCurrentElementState('add');
  362. $admin_primary_cash_request->processRequest(
  363. array(
  364. 'cash_request_type' => 'element',
  365. 'cash_action' => 'addelement',
  366. 'name' => $post_data['element_name'],
  367. 'type' => $post_data['element_type'],
  368. 'options_data' => $options_array,
  369. 'user_id' => AdminHelper::getPersistentData('cash_effective_user')
  370. )
  371. );
  372. if ($admin_primary_cash_request->response['status_uid'] == 'element_addelement_200') {
  373. $current_campaign = false;
  374. if ($post_data['in_campaign']) {
  375. $current_campaign = $post_data['in_campaign'];
  376. } else {
  377. $current_campaign = AdminHelper::getPersistentData('current_campaign');
  378. }
  379. if ($current_campaign) {
  380. $cash_admin->requestAndStore(
  381. array(
  382. 'cash_request_type' => 'element',
  383. 'cash_action' => 'addelementtocampaign',
  384. 'campaign_id' => $current_campaign,
  385. 'element_id' => $admin_primary_cash_request->response['payload']
  386. )
  387. );
  388. // handle differently for AJAX and non-AJAX
  389. if ($cash_admin->page_data['data_only']) {
  390. AdminHelper::formSuccess('Success. New element added.','/');
  391. } else {
  392. $cash_admin->setCurrentElement($admin_primary_cash_request->response['payload']);
  393. }
  394. } else {
  395. // handle differently for AJAX and non-AJAX
  396. if ($cash_admin->page_data['data_only']) {
  397. AdminHelper::formSuccess('Success. New element added.','/elements/edit/' . $admin_primary_cash_request->response['payload']);
  398. } else {
  399. $cash_admin->setCurrentElement($admin_primary_cash_request->response['payload']);
  400. }
  401. }
  402. } else {
  403. // handle differently for AJAX and non-AJAX
  404. if ($cash_admin->page_data['data_only']) {
  405. AdminHelper::formFailure('Error. Something just didn\'t work right.','/elements/add/' . $post_data['element_type']);
  406. } else {
  407. $cash_admin->setErrorState('element_add_failure');
  408. }
  409. }
  410. } elseif (isset($post_data['doelementedit'])) {
  411. // Editing an existing element:
  412. $cash_admin->setCurrentElementState('edit');
  413. $admin_primary_cash_request->processRequest(
  414. array(
  415. 'cash_request_type' => 'element',
  416. 'cash_action' => 'editelement',
  417. 'id' => $post_data['element_id'],
  418. 'name' => $post_data['element_name'],
  419. 'options_data' => $options_array
  420. )
  421. );
  422. if ($admin_primary_cash_request->response['status_uid'] == 'element_editelement_200') {
  423. // handle differently for AJAX and non-AJAX
  424. if ($cash_admin->page_data['data_only']) {
  425. // AJAX
  426. AdminHelper::formSuccess('Success. Edited.','/elements/edit/' . $post_data['element_id']);
  427. } else {
  428. // non-AJAX
  429. $cash_admin->setCurrentElement($post_data['element_id']);
  430. }
  431. } else {
  432. // handle differently for AJAX and non-AJAX
  433. if ($cash_admin->page_data['data_only']) {
  434. // AJAX
  435. AdminHelper::formFailure('Error. Something just didn\'t work right.','/elements/edit/' . $post_data['element_id']);
  436. } else {
  437. // non-AJAX
  438. $cash_admin->setErrorState('element_edit_failure');
  439. }
  440. }
  441. }
  442. AdminHelper::setBasicElementFormData($cash_admin);
  443. }
  444. }
  445. public static function setBasicElementFormData(&$cash_admin) {
  446. $current_element = $cash_admin->getCurrentElement();
  447. if ($current_element) {
  448. // Current element found, so fill in the 'edit' form:
  449. $cash_admin->page_data['element_id'] = $current_element['id'];
  450. $cash_admin->page_data['element_name'] = $current_element['name'];
  451. }
  452. }
  453. /**
  454. * Finds settings matching a specified scope and echoes them out formatted
  455. * for a dropdown box in a form
  456. *
  457. */public static function echoTemplateOptions($type='page',$selected=null,$return=true) {
  458. global $cash_admin;
  459. $templates_array = array(
  460. array(
  461. 'id' => -2,
  462. 'name' => 'Use dark theme'
  463. ),
  464. array(
  465. 'id' => -1,
  466. 'name' => 'Use light theme'
  467. ),
  468. array(
  469. 'id' => 0,
  470. 'name' => 'Custom'
  471. )
  472. );
  473. if ($selected === null) {
  474. $selected = -2;
  475. } else {
  476. if ($selected > 0) {
  477. $templates_array[2]['id'] = $selected;
  478. }
  479. }
  480. $all_templates = '';
  481. foreach ($templates_array as $template) {
  482. $echo_selected = '';
  483. if ($template['id'] == $selected) { $echo_selected = ' selected="selected"'; }
  484. $all_templates .= '<option value="' . $template['id'] . '"' . $echo_selected . '>' . $template['name'] . '</option>';
  485. }
  486. if ($return) {
  487. return $all_templates;
  488. } else {
  489. echo $all_templates;
  490. }
  491. }
  492. /**********************************************
  493. *
  494. * SIMPLE DATA FORMATTING
  495. *
  496. *********************************************/
  497. public static function createdModifiedFromRow($row,$top=false) {
  498. $addtoclass = '';
  499. if ($top) { $addtoclass = '_top'; }
  500. $markup = '<div class="smalltext fadedtext created_mod' . $addtoclass . '">Created: ' . date('M jS, Y',$row['creation_date']);
  501. if ($row['modification_date']) {
  502. $markup .= ' (Modified: ' . date('F jS, Y',$row['modification_date']) . ')';
  503. }
  504. $markup .= '</div>';
  505. return $markup;
  506. }
  507. /**
  508. * Spit out human readable byte size
  509. * swiped from comments: http://us2.php.net/manual/en/function.memory-get-usage.php
  510. *
  511. * @param $bytes (int)
  512. * @param $precision (int)
  513. * @return string
  514. */function bytesToSize($bytes, $precision = 2) {
  515. $unit = array('B','KB','MB','GB','TB','PB','EB');
  516. if (!$bytes) {
  517. return 'unknown';
  518. }
  519. return @round($bytes / pow(1024, ($i = floor(log($bytes, 1024)))), $precision) . ' ' . $unit[$i];
  520. }
  521. /**********************************************
  522. *
  523. * MISCELLANEOUS
  524. *
  525. *********************************************/
  526. public static function parseMetaData($post_data) {
  527. $metadata_and_tags = array(
  528. 'metadata_details' => array(),
  529. 'tags_details' => array()
  530. );
  531. foreach ($post_data as $key => $value) {
  532. if (substr($key,0,3) == 'tag' && $value !== '') {
  533. $metadata_and_tags['tags_details'][] = $value;
  534. $metadata_and_tags['total_tags'] = count($metadata_and_tags['tags_details']);
  535. }
  536. if (substr($key,0,11) == 'metadatakey' && $value !== '') {
  537. $metadatavalue = $_POST[str_replace('metadatakey','metadatavalue',$key)];
  538. if ($metadatavalue) {
  539. $metadata_and_tags['metadata_details'][$value] = $metadatavalue;
  540. }
  541. }
  542. }
  543. return $metadata_and_tags;
  544. }
  545. /**
  546. * Performs a sessionGet() CASH Request for the specified variable
  547. *
  548. */public static function getPersistentData($var) {
  549. global $admin_primary_cash_request;
  550. $result = $admin_primary_cash_request->sessionGet($var);
  551. return $result;
  552. }
  553. public static function getActivity($current_userdata=false) {
  554. global $admin_primary_cash_request, $cash_admin;
  555. $session_news = $admin_primary_cash_request->sessionGet('admin_newsfeed');
  556. if (!$session_news) {
  557. /*
  558. $tumblr_seed = new TumblrSeed();
  559. $tumblr_request = $tumblr_seed->getTumblrFeed('blog.cashmusic.org',0,'platformnews');
  560. $dashboard_news_img = null;
  561. $dashboard_news = "<p>News could not be read. So let's say no news is good news.</p>";
  562. $doc = new DOMDocument();
  563. @$doc->loadHTML($tumblr_request[0]->{'regular-body'});
  564. $imgs = $doc->getElementsByTagName('img');
  565. if ($imgs->length) {
  566. $dashboard_news_img = $imgs->item(0)->getAttribute('src');
  567. }
  568. $ps = $doc->getElementsByTagName('p');
  569. foreach ($ps as $p) {
  570. if ($p->nodeValue) {
  571. $dashboard_news = '<p><b><i>' . $tumblr_request[0]->{$tumblr_request[0]->type . '-title'} . ':</i></b> ' .
  572. $p->nodeValue . ' <a href="' . $tumblr_request[0]->{'url-with-slug'} . '" class="usecolor1" target="_blank">' . 'Read more.</a></p>';
  573. break;
  574. }
  575. }
  576. if ($tumblr_request[0]->{'unix-timestamp'} > (time() - 604800)) {
  577. // store all that tumblr junk in our array and move on
  578. $session_news = array(
  579. 'cash_news_date' => $tumblr_request[0]->{'unix-timestamp'},
  580. 'cash_news_content' => $dashboard_news,
  581. 'cash_news_img' => $dashboard_news_img
  582. );
  583. } else {
  584. $session_news = array(
  585. 'cash_news_date' => false,
  586. 'cash_news_content' => false,
  587. 'cash_news_img' => false
  588. );
  589. }
  590. */
  591. $last_login = 0;
  592. if (is_array($current_userdata)) {
  593. if (array_key_exists('last_login', $current_userdata)) {
  594. $last_login = $current_userdata['last_login'];
  595. }
  596. }
  597. // get recent activity
  598. $activity_request = new CASHRequest(
  599. array(
  600. 'cash_request_type' => 'people',
  601. 'cash_action' => 'getrecentactivity',
  602. 'user_id' => $cash_admin->effective_user_id,
  603. 'since_date' => $last_login
  604. )
  605. );
  606. $activity = $activity_request->response['payload'];
  607. $session_news['activity'] = $activity;
  608. // store it in the session for later
  609. $admin_primary_cash_request->sessionSet('admin_newsfeed',$session_news);
  610. }
  611. return $session_news;
  612. }
  613. /**********************************************
  614. *
  615. * FORM HELPER FUNCTIONS
  616. *
  617. *********************************************/
  618. public static function controllerRedirect($location) {
  619. if (isset($_REQUEST['data_only'])) {
  620. echo json_encode(
  621. array(
  622. 'doredirect' => true,
  623. 'location' => ADMIN_WWW_BASE_PATH . $location
  624. )
  625. );
  626. exit();
  627. } else {
  628. header('Location: ' . ADMIN_WWW_BASE_PATH . $location);
  629. }
  630. }
  631. public static function formSuccess($message=false,$location=false) {
  632. if (!$location) {
  633. global $admin_primary_cash_request;
  634. $location = $admin_primary_cash_request->sessionGet('last_route');
  635. if (!$location) {
  636. $location = REQUESTED_ROUTE;
  637. }
  638. }
  639. if (isset($_REQUEST['forceroute'])) {
  640. // we force a route using JS for certain lightboxed forms — really used
  641. // as an override that should take precenece over the standard $location
  642. $location = $_REQUEST['forceroute'];
  643. }
  644. if (isset($_REQUEST['data_only'])) {
  645. echo json_encode(
  646. array(
  647. 'doredirect' => true,
  648. 'location' => ADMIN_WWW_BASE_PATH . $location,
  649. 'showmessage' => $message
  650. )
  651. );
  652. exit();
  653. } else {
  654. if ($location == REQUESTED_ROUTE) {
  655. if ($message) {
  656. global $cash_admin;
  657. $cash_admin->page_data['page_message'] = $message;
  658. }
  659. } else {
  660. header('Location: ' . ADMIN_WWW_BASE_PATH . $location);
  661. }
  662. }
  663. }
  664. public static function formFailure($error_message,$location=false) {
  665. if (!$location) {
  666. global $admin_primary_cash_request;
  667. $location = $admin_primary_cash_request->sessionGet('last_route');
  668. if (!$location) {
  669. $location = REQUESTED_ROUTE;
  670. }
  671. }
  672. if (isset($_REQUEST['forceroute'])) {
  673. // we force a route using JS for certain lightboxed forms — really used
  674. // as an override that should take precenece over the standard $location
  675. $location = $_REQUEST['forceroute'];
  676. }
  677. if (isset($_REQUEST['data_only'])) {
  678. if ($location == '//') {
  679. $location = '/';
  680. }
  681. echo json_encode(
  682. array(
  683. 'doredirect' => true,
  684. 'location' => ADMIN_WWW_BASE_PATH . $location,
  685. 'showerror' => $error_message
  686. )
  687. );
  688. exit();
  689. } else {
  690. global $cash_admin;
  691. $cash_admin->page_data['error_message'] = $error_message;
  692. }
  693. }
  694. public static function drawCountryCodeUL($selected='USA') {
  695. $all_codes = array(
  696. 'USA','Brazil','Canada','Czech Republic','France','Germany','Italy','Japan','United Kingdom',
  697. '',
  698. 'Afghanistan',
  699. 'Albania',
  700. 'Algeria',
  701. 'Andorra',
  702. 'Angola',
  703. 'Antigua &amp; Deps',
  704. 'Argentina',
  705. 'Armenia',
  706. 'Australia',
  707. 'Austria',
  708. 'Azerbaijan',
  709. 'Bahamas',
  710. 'Bahrain',
  711. 'Bangladesh',
  712. 'Barbados',
  713. 'Belarus',
  714. 'Belgium',
  715. 'Belize',
  716. 'Benin',
  717. 'Bhutan',
  718. 'Bolivia',
  719. 'Bosnia Herzegovina',
  720. 'Botswana',
  721. 'Brazil',
  722. 'Brunei',
  723. 'Bulgaria',
  724. 'Burkina',
  725. 'Burundi',
  726. 'Cambodia',
  727. 'Cameroon',
  728. 'Canada',
  729. 'Cape Verde',
  730. 'Central African Rep',
  731. 'Chad',
  732. 'Chile',
  733. 'China',
  734. 'Colombia',
  735. 'Comoros',
  736. 'Congo',
  737. 'Costa Rica',
  738. 'Croatia',
  739. 'Cuba',
  740. 'Cyprus',
  741. 'Czech Republic',
  742. 'Denmark',
  743. 'Djibouti',
  744. 'Dominica',
  745. 'Dominican Republic',
  746. 'East Timor',
  747. 'Ecuador',
  748. 'Egypt',
  749. 'El Salvador',
  750. 'Equatorial Guinea',
  751. 'Eritrea',
  752. 'Estonia',
  753. 'Ethiopia',
  754. 'Fiji',
  755. 'Finland',
  756. 'France',
  757. 'Gabon',
  758. 'Gambia',
  759. 'Georgia',
  760. 'Germany',
  761. 'Ghana',
  762. 'Greece',
  763. 'Grenada',
  764. 'Guatemala',
  765. 'Guinea',
  766. 'Guinea-Bissau',
  767. 'Guyana',
  768. 'Haiti',
  769. 'Honduras',
  770. 'Hungary',
  771. 'Iceland',
  772. 'India',
  773. 'Indonesia',
  774. 'Iran',
  775. 'Iraq',
  776. 'Ireland',
  777. 'Israel',
  778. 'Italy',
  779. 'Ivory Coast',
  780. 'Jamaica',
  781. 'Japan',
  782. 'Jordan',
  783. 'Kazakhstan',
  784. 'Kenya',
  785. 'Kiribati',
  786. 'Korea North',
  787. 'Korea South',
  788. 'Kosovo',
  789. 'Kuwait',
  790. 'Kyrgyzstan',
  791. 'Laos',
  792. 'Latveria',
  793. 'Latvia',
  794. 'Lebanon',
  795. 'Lesotho',
  796. 'Liberia',
  797. 'Libya',
  798. 'Liechtenstein',
  799. 'Lithuania',
  800. 'Luxembourg',
  801. 'Macedonia',
  802. 'Madagascar',
  803. 'Malawi',
  804. 'Malaysia',
  805. 'Maldives',
  806. 'Mali',
  807. 'Malta',
  808. 'Marshall Islands',
  809. 'Mauritania',
  810. 'Mauritius',
  811. 'Mexico',
  812. 'Micronesia',
  813. 'Moldova',
  814. 'Monaco',
  815. 'Mongolia',
  816. 'Montenegro',
  817. 'Morocco',
  818. 'Mozambique',
  819. 'Myanmar, (Burma)',
  820. 'Namibia',
  821. 'Nauru',
  822. 'Nepal',
  823. 'Netherlands',
  824. 'New Zealand',
  825. 'Nicaragua',
  826. 'Niger',
  827. 'Nigeria',
  828. 'Norway',
  829. 'Oman',
  830. 'Pakistan',
  831. 'Palau',
  832. 'Panama',
  833. 'Papua New Guinea',
  834. 'Paraguay',
  835. 'Peru',
  836. 'Philippines',
  837. 'Poland',
  838. 'Portugal',
  839. 'Qatar',
  840. 'Romania',
  841. 'Russian Federation',
  842. 'Rwanda',
  843. 'St Kitts &amp; Nevis',
  844. 'St Lucia',
  845. 'Saint Vincent &amp; the Grenadines',
  846. 'Samoa',
  847. 'San Marino',
  848. 'Sao Tome &amp; Principe',
  849. 'Saudi Arabia',
  850. 'Senegal',
  851. 'Serbia',
  852. 'Seychelles',
  853. 'Sierra Leone',
  854. 'Singapore',
  855. 'Slovakia',
  856. 'Slovenia',
  857. 'Solomon Islands',
  858. 'Somalia',
  859. 'South Africa',
  860. 'Spain',
  861. 'Sri Lanka',
  862. 'Sudan',
  863. 'Suriname',
  864. 'Swaziland',
  865. 'Sweden',
  866. 'Switzerland',
  867. 'Syria',
  868. 'Taiwan',
  869. 'Tajikistan',
  870. 'Tanzania',
  871. 'Thailand',
  872. 'Togo',
  873. 'Tonga',
  874. 'Trinidad &amp; Tobago',
  875. 'Tunisia',
  876. 'Turkey',
  877. 'Turkmenistan',
  878. 'Tuvalu',
  879. 'Uganda',
  880. 'Ukraine',
  881. 'United Arab Emirates',
  882. 'United Kingdom',
  883. 'United States',
  884. 'Uruguay',
  885. 'Uzbekistan',
  886. 'Vanuatu',
  887. 'Vatican City',
  888. 'Venezuela',
  889. 'Vietnam',
  890. 'Yemen',
  891. 'Zambia',
  892. 'Zimbabwe'
  893. );
  894. $all_options = '';
  895. $has_selected = false;
  896. foreach ($all_codes as $code) {
  897. $all_options .= '<option value="' . $code . '"';
  898. if (!$has_selected && $code == $selected) {
  899. $all_options .= ' selected="selected"';
  900. $has_selected = true;
  901. }
  902. $all_options .= '>' . $code . '</option>';
  903. }
  904. return $all_options;
  905. }
  906. public static function drawTimeZones($selected='US/Pacific') {
  907. $all_zones = array(
  908. 'US/Alaska',
  909. 'US/Arizona',
  910. 'US/Central',
  911. 'US/East-Indiana',
  912. 'US/Eastern',
  913. 'US/Hawaii',
  914. 'US/Mountain',
  915. 'US/Pacific',
  916. 'US/Samoa',
  917. 'Africa/Cairo',
  918. 'Africa/Casablanca',
  919. 'Africa/Harare',
  920. 'Africa/Monrovia',
  921. 'Africa/Nairobi',
  922. 'America/Bogota',
  923. 'America/Buenos_Aires',
  924. 'America/Caracas',
  925. 'America/Chihuahua',
  926. 'America/La_Paz',
  927. 'America/Lima',
  928. 'America/Mazatlan',
  929. 'America/Mexico_City',
  930. 'America/Monterrey',
  931. 'America/Santiago',
  932. 'America/Tijuana',
  933. 'Asia/Almaty',
  934. 'Asia/Baghdad',
  935. 'Asia/Baku',
  936. 'Asia/Bangkok',
  937. 'Asia/Chongqing',
  938. 'Asia/Dhaka',
  939. 'Asia/Hong_Kong',
  940. 'Asia/Irkutsk',
  941. 'Asia/Jakarta',
  942. 'Asia/Jerusalem',
  943. 'Asia/Kabul',
  944. 'Asia/Kamchatka',
  945. 'Asia/Karachi',
  946. 'Asia/Kathmandu',
  947. 'Asia/Kolkata',
  948. 'Asia/Krasnoyarsk',
  949. 'Asia/Kuala_Lumpur',
  950. 'Asia/Kuwait',
  951. 'Asia/Magadan',
  952. 'Asia/Muscat',
  953. 'Asia/Novosibirsk',
  954. 'Asia/Riyadh',
  955. 'Asia/Seoul',
  956. 'Asia/Singapore',
  957. 'Asia/Taipei',
  958. 'Asia/Tashkent',
  959. 'Asia/Tbilisi',
  960. 'Asia/Tehran',
  961. 'Asia/Tokyo',
  962. 'Asia/Ulaanbaatar',
  963. 'Asia/Urumqi',
  964. 'Asia/Vladivostok',
  965. 'Asia/Yakutsk',
  966. 'Asia/Yekaterinburg',
  967. 'Asia/Yerevan',
  968. 'Atlantic/Azores',
  969. 'Atlantic/Cape_Verde',
  970. 'Atlantic/Stanley',
  971. 'Australia/Adelaide',
  972. 'Australia/Brisbane',
  973. 'Australia/Canberra',
  974. 'Australia/Darwin',
  975. 'Australia/Hobart',
  976. 'Australia/Melbourne',
  977. 'Australia/Perth',
  978. 'Australia/Sydney',
  979. 'Canada/Atlantic',
  980. 'Canada/Newfoundland',
  981. 'Canada/Saskatchewan',
  982. 'Europe/Amsterdam',
  983. 'Europe/Athens',
  984. 'Europe/Belgrade',
  985. 'Europe/Berlin',
  986. 'Europe/Bratislava',
  987. 'Europe/Brussels',
  988. 'Europe/Bucharest',
  989. 'Europe/Budapest',
  990. 'Europe/Copenhagen',
  991. 'Europe/Dublin',
  992. 'Europe/Helsinki',
  993. 'Europe/Istanbul',
  994. 'Europe/Kiev',
  995. 'Europe/Lisbon',
  996. 'Europe/Ljubljana',
  997. 'Europe/London',
  998. 'Europe/Madrid',
  999. 'Europe/Minsk',
  1000. 'Europe/Moscow',
  1001. 'Europe/Paris',
  1002. 'Europe/Prague',
  1003. 'Europe/Riga',
  1004. 'Europe/Rome',
  1005. 'Europe/Sarajevo',
  1006. 'Europe/Skopje',
  1007. 'Europe/Sofia',
  1008. 'Europe/Stockholm',
  1009. 'Europe/Tallinn',
  1010. 'Europe/Vienna',
  1011. 'Europe/Vilnius',
  1012. 'Europe/Volgograd',
  1013. 'Europe/Warsaw',
  1014. 'Europe/Zagreb',
  1015. 'Greenland',
  1016. 'Pacific/Auckland',
  1017. 'Pacific/Fiji',
  1018. 'Pacific/Guam',
  1019. 'Pacific/Midway',
  1020. 'Pacific/Port_Moresby'
  1021. );
  1022. $all_options = '';
  1023. $has_selected = false;
  1024. foreach ($all_zones as $zone) {
  1025. $all_options .= '<option value="' . $zone . '"';
  1026. if (!$has_selected && $zone == $selected) {
  1027. $all_options .= ' selected="selected"';
  1028. $has_selected = true;
  1029. }
  1030. $all_options .= '>' . $zone . '</option>';
  1031. }
  1032. return $all_options;
  1033. }
  1034. /**
  1035. * Tell it what you need. It makes dropdowns. It's a dropdown robot travelling
  1036. * at the speed of light — it'll make a supersonic nerd of you. Don't stop it.
  1037. *
  1038. * @return array
  1039. */public static function echoFormOptions($base_type,$selected=0,$range=false,$return=false) {
  1040. global $admin_primary_cash_request;
  1041. $available_options = false;
  1042. if (is_array($base_type)) {
  1043. $available_options = array();
  1044. foreach ($base_type as $key => $value) {
  1045. $available_options[] = array(
  1046. 'id' => $key,
  1047. 'display' => $value
  1048. );
  1049. }
  1050. $display_information = 'display';
  1051. $all_options = '';
  1052. } else {
  1053. if (substr($base_type,0,7) == 'connect') {
  1054. $scope = explode('_',$base_type);
  1055. return AdminHelper::echoConnectionsOptions($scope[1],$selected,true);
  1056. }
  1057. $all_options = '<option value="0">None</option>';
  1058. switch ($base_type) {
  1059. case 'assets':
  1060. $plant_name = 'asset';
  1061. $action_name = 'getassetsforuser';
  1062. $display_information = 'title';
  1063. if ($range) {
  1064. if (!in_array($selected,$range)) {
  1065. $range[] = $selected;
  1066. }
  1067. }
  1068. break;
  1069. case 'people_lists':
  1070. $plant_name = 'people';
  1071. $action_name = 'getlistsforuser';
  1072. $display_information = 'name';
  1073. break;
  1074. case 'venues':
  1075. case 'calendar_venues':
  1076. $plant_name = 'calendar';
  1077. $action_name = 'getallvenues';
  1078. $display_information = 'name';
  1079. break;
  1080. case 'items':
  1081. case 'commerce_items':
  1082. $plant_name = 'commerce';
  1083. $action_name = 'getitemsforuser';
  1084. $display_information = 'name';
  1085. break;
  1086. }
  1087. global $admin_primary_cash_request;
  1088. $admin_primary_cash_request->processRequest(
  1089. array(
  1090. 'cash_request_type' => $plant_name,
  1091. 'cash_action' => $action_name,
  1092. 'user_id' => AdminHelper::getPersistentData('cash_effective_user'),
  1093. 'parent_id' => 0
  1094. )
  1095. );
  1096. if (is_array($admin_primary_cash_request->response['payload']) && ($admin_primary_cash_request->response['status_code'] == 200)) {
  1097. $available_options = $admin_primary_cash_request->response['payload'];
  1098. }
  1099. }
  1100. if (is_array($available_options)) {
  1101. foreach ($available_options as $item) {
  1102. $doloop = true;
  1103. if ($range) {
  1104. if (!in_array($item['id'],$range)) {
  1105. $doloop = false;
  1106. }
  1107. }
  1108. if ($doloop) {
  1109. $selected_string = '';
  1110. if ($item['id'] === $selected) {
  1111. $selected_string = ' selected="selected"';
  1112. }
  1113. $all_options .= '<option value="' . $item['id'] . '"' . $selected_string . '>' . $item[$display_information] . '</option>';
  1114. }
  1115. }
  1116. } else {
  1117. $all_options = false;
  1118. }
  1119. if ($return) {
  1120. return $all_options;
  1121. } else {
  1122. echo $all_options;
  1123. }
  1124. }
  1125. /**
  1126. * MONIES
  1127. *
  1128. * @return array
  1129. */public static function echoCurrencyOptions($selected='USD') {
  1130. $currencies = CASHSystem::getCurrencySymbol('all');
  1131. $all_options = '';
  1132. $has_selected = false;
  1133. foreach ($currencies as $currency => $symbol) {
  1134. $all_options .= '<option value="' . $currency . '"';
  1135. if (!$has_selected && $currency == $selected) {
  1136. $all_options .= ' selected="selected"';
  1137. $has_selected = true;
  1138. }
  1139. $all_options .= '>' . $currency . ' / ' . $symbol . '</option>';
  1140. }
  1141. return $all_options;
  1142. }
  1143. } // END class
  1144. ?>