PageRenderTime 50ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/include/Modules/UDM/QuickForm/BuildAdmin.inc.php

https://github.com/radicaldesigns/amp
PHP | 691 lines | 283 code | 113 blank | 295 comment | 33 complexity | ff32834b471c7cb213fdb7b3eea33a08 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, BSD-3-Clause, LGPL-2.0, CC-BY-SA-3.0, AGPL-1.0
  1. <?php
  2. /*****
  3. *
  4. * AMP UserDataModule HTML_QuickForm builder Plugin
  5. *
  6. * Creates an HTML_QuickForm object based on the contents of
  7. * an UDM object.
  8. *
  9. *****/
  10. require_once( 'HTML/QuickForm.php' );
  11. require_once( 'HTML/QuickForm/Renderer/Savant.php' );
  12. require_once( 'Savant/Savant2.php' );
  13. require_once( 'AMP/UserData/Plugin.inc.php' );
  14. require_once( 'AMP/UserData/Lookups.inc.php');
  15. class UserDataPlugin_BuildAdmin_QuickForm extends UserDataPlugin {
  16. var $fields = Array();
  17. var $form;
  18. var $regions;
  19. var $_field_plugin_def = array(
  20. 'priority' => array(
  21. 'type' => 'text',
  22. 'size' => '2',
  23. 'default' => null,
  24. 'label' => 'Priority' ),
  25. 'active' => array(
  26. 'type' => 'checkbox',
  27. 'value' => true,
  28. 'label' => 'Active'),
  29. /* 'remove' => array(
  30. 'type' => 'checkbox',
  31. 'label' => 'Remove'),*/
  32. 'id' => array(
  33. 'available' => true,
  34. 'default' => null,
  35. 'type' => 'hidden' ));
  36. var $available = false;
  37. function UserDataPlugin_BuildAdmin_QuickForm ( &$udm ) {
  38. $this->init( $udm );
  39. }
  40. function execute ( $options = array( )) {
  41. $form_name = $this->udm->name;
  42. $form_method = ( isset($options['frmMethod']) ) ?
  43. $options['frmMethod'] : 'post';
  44. $form_action = ( isset($options['frmAction']) ) ?
  45. $options['frmAction'] : null;
  46. $this->form = new HTML_QuickForm( $form_name, $form_method, $form_action );
  47. $this->form->addElement( 'hidden', 'modin', 'Module Instance' );
  48. $this->form->addElement( 'submit', 'btnUdmSubmit', 'Submit' );
  49. $this->form->registerElementType('multiselect', 'HTML/QuickForm/select.php', 'HTML_QuickForm_select');
  50. $this->form->registerElementType('radiogroup', 'HTML/QuickForm/group.php', 'HTML_QuickForm_group' );
  51. $this->form->registerElementType('checkgroup', 'HTML/QuickForm/group.php', 'HTML_QuickForm_group' );
  52. $this->form->registerElementType('wysiwyg', 'HTML/QuickForm/textarea.php', 'HTML_QuickForm_textarea');
  53. $this->form->registerElementType('captcha', 'HTML/QuickForm/text.php', 'HTML_QuickForm_text' );
  54. $this->form->registerElementType('imagepicker', 'HTML/QuickForm/select.php', 'HTML_QuickForm_select');
  55. $this->_build_core_fields();
  56. $this->_build_fields();
  57. $this->_build_plugins();
  58. $this->_build_preview();
  59. $opener = &$this->form->addElement( 'button', 'open_up', 'Expand All Fields' );
  60. $opener->updateAttributes( array( 'onclick' => 'change_all_udm_blocks( );' ));
  61. $this->form->setDefaults( $this->udm->_module_def );
  62. $this->form->setConstants( array( 'modin' => $this->udm->instance ) );
  63. $tpl = new Savant2();
  64. $tpl->addPath('template', $_SERVER['DOCUMENT_ROOT'] . '/include/templates/UserData');
  65. $renderer = new HTML_QuickForm_Renderer_Savant(false, false, $tpl);
  66. $renderer->setTemplate('admin.php.tpl');
  67. $this->form->accept($renderer);
  68. $this->udm->form = $this->form;
  69. }
  70. function _build_form ( $fields, $prefix = '' ) {
  71. if ($prefix) $prefix .= "_";
  72. foreach ( $fields as $field_name => $field ) {
  73. $label = (isset($field['label'])) ? $field['label'] : null;
  74. $values = (isset($field['values'])) ? $field['values'] : null;
  75. $el = &$this->form->addElement( $field['type'],
  76. $prefix . $field_name,
  77. $label,
  78. $values );
  79. if ( isset( $field['size']) && $field['type'] == 'text') $el->setSize( $field['size']);
  80. if ( $field['type'] == 'textarea') {
  81. $el->setRows( 5 );
  82. $el->setCols( 50 );
  83. }
  84. if ( $field['type'] == 'multiselect') {
  85. $el->setMultiple( true );
  86. if ( isset( $field['size'])) {
  87. $el->setSize( $field['size']);
  88. }
  89. }
  90. }
  91. }
  92. function _read_plugins( ){
  93. $plugins = $this->udm->plugins;
  94. $option_values = array( );
  95. $plugin_settings = array( );
  96. $plugin_ids = array( );
  97. $plugin_priorities = FormLookup::instance( 'pluginPriorities');
  98. foreach( $plugins as $action => $plugin_def ){
  99. foreach( $plugin_def as $namespace => $plugin ){
  100. $prefix = join( '_', array( 'plugin', $action, $namespace ));
  101. if ( !$plugin->plugin_instance ) continue;
  102. $plugin_ids[ $prefix . '_plugin_id'] = $plugin->plugin_instance;
  103. $plugin_settings[ $prefix . '_plugin_priority'] = $plugin_priorities[ $plugin->plugin_instance ];
  104. $plugin_settings[ $prefix . '_plugin_active'] = true;
  105. }
  106. }
  107. $this->form->setDefaults( $plugin_settings );
  108. $this->form->setDefaults( $plugin_ids );
  109. $this->form->setConstants( $plugin_ids );
  110. }
  111. function _build_core_fields () {
  112. $dbcon = $this->udm->dbcon;
  113. $modules_blank_row[ '' ] = '--';
  114. $modules = $modules_blank_row + FormLookup_IntroTexts::instance( $this->udm->instance );
  115. $lists_blank_row[ '' ] = 'none';
  116. $lists = $lists_blank_row;
  117. if( $available_lists = AMP_lookup( 'lists' )) {
  118. $lists = $lists_blank_row + $available_lists;
  119. }
  120. $fields = $this->fields;
  121. $fields['core'] = Array( 'tab' => array( 'type' => 'header', 'label' => 'Settings', 'values' => 'Settings' ) );
  122. $fields['core']['name'] = array( 'label' => 'Name', 'type' => 'text' );
  123. $fields['core']['publish'] = array( 'label' => 'Publish List', 'type' => 'checkbox' );
  124. $fields['core']['publish_form'] = array( 'label' => 'Publish Form', 'type' => 'checkbox' );
  125. $fields['core']['modidinput'] = array( 'label' => 'Intro Text', 'type' => 'select', 'values' => $modules );
  126. $fields['core']['modidresponse'] = array( 'label' => 'Response Text', 'type' => 'select', 'values' => $modules );
  127. $fields['core']['uselists'] = array( 'label' => 'Use Lists', 'type' => 'checkbox' );
  128. if( $available_lists ) {
  129. $fields['core']['list1'] = array( 'label' => 'List #1', 'type' => 'select', 'values' => $lists );
  130. $fields['core']['list2'] = array( 'label' => 'List #2', 'type' => 'select', 'values' => $lists );
  131. $fields['core']['list3'] = array( 'label' => 'List #3', 'type' => 'select', 'values' => $lists );
  132. $fields['core']['list4'] = array( 'label' => 'List #4', 'type' => 'select', 'values' => $lists );
  133. }
  134. $fields['core']['useemail'] = array( 'label' => 'Use E-Mail', 'type' => 'checkbox' );
  135. $fields['core']['mailto'] = array( 'label' => 'Mail to', 'type' => 'text' );
  136. $fields['core']['subject'] = array( 'label' => 'E-mail Subject', 'type' => 'text' );
  137. $fields['core']['field_order'] = array( 'label' => 'Field Order', 'type' => 'textarea' );
  138. // Fixup the module definition to account for different names.
  139. $md = &$this->udm->_module_def;
  140. foreach ( array_keys( $fields['core'] ) as $field ) {
  141. if ( isset( $md[$field] ) ) {
  142. $md[ "core_$field" ] = $md[ $field ];
  143. }
  144. }
  145. $this->_build_form( $fields['core'], 'core' );
  146. }
  147. function _build_fields () {
  148. $fields = $this->fields;
  149. $fields['standard'] = Array( 'standard_tab' => array( 'type' => 'header', 'label' => 'Standard Fields', 'values' => 'Standard Fields' ) );
  150. $fields['custom'] = Array( 'custom_tab' => array( 'type' => 'header', 'label' => 'Custom Fields', 'values' => 'Custom Fields' ) );
  151. foreach ( $this->udm->fields as $field_name => $field ) {
  152. if ( strpos($field_name, "custom") === 0 ) {
  153. $group = 'custom';
  154. } elseif ( strpos($field_name, "plugin") === 0 ) {
  155. # Plugin fields are handled elsewhere.
  156. continue;
  157. } else {
  158. $group = 'standard';
  159. }
  160. $fields[$group] += $this->_build_field( $field_name, $field );
  161. }
  162. $this->_build_form( $fields['standard'] );
  163. $this->_build_form( $fields['custom'] );
  164. }
  165. function _build_plugins () {
  166. $actions = $this->udm->getPlugins();
  167. $fields = $this->fields;
  168. $this->_build_form( Array( 'plugins_tab' => Array( 'type' => 'header', 'values' => 'Plugins' ) ) );
  169. // because it's a hierselect, it just adds the field to the form.
  170. $this->_build_plugins_add();
  171. // We use this to fill in default values.
  172. $md = &$this->udm->_module_def;
  173. $plugin_priorities = FormLookup::instance( 'pluginPriorities');
  174. foreach ( $actions as $action => $plugins ) {
  175. foreach ( $plugins as $namespace => $plugin ) {
  176. # Skip plugins that aren't available for modification.
  177. if (!$plugin->available) continue;
  178. $plugin_fields = $fields['plugins'][$action][$namespace];
  179. $plugin_name = "plugin_$action" . "_$namespace";
  180. $plugin_fields = Array();
  181. $option_values = $plugin->getOptions( );
  182. if (isset( $plugin->options )) {
  183. foreach ( $plugin->options as $option_name => $option ) {
  184. if (!isset($option['available']) || !$option['available']) continue;
  185. $plugin_fields[$option_name] = $option;
  186. if ( isset( $option_values[$option_name])) {
  187. $md[$plugin_name . "_$option_name"] = $option_values[ $option_name ];
  188. }
  189. }
  190. }
  191. foreach( $this->_field_plugin_def as $short_name => $field_def ){
  192. $field_name = 'plugin_' . $short_name ;
  193. $plugin_fields[ $field_name ] = $field_def ;
  194. }
  195. $md[$plugin_name . "_plugin_active"] = true;
  196. if ( $plugin->plugin_instance ) {
  197. $md[$plugin_name . "_plugin_id"] = $plugin->plugin_instance;
  198. $md[$plugin_name . "_plugin_priority"] = $plugin_priorities[ $plugin->plugin_instance ];
  199. $plugin_fields[ 'plugin_id']['default'] = $plugin->plugin_instance;
  200. $plugin_fields[ 'plugin_priority']['default'] = $plugin_priorities[ $plugin->plugin_instance ];
  201. }
  202. /* this is deprecated, i hope we never implement it
  203. if (isset( $plugin->fields )) {
  204. foreach ( $plugin->fields as $field_name => $field ) {
  205. $plugin_fields[$field_name] = $this->_build_field( $field_name, $field );
  206. }
  207. }
  208. */
  209. if (count($plugin_fields) > 0) {
  210. $header = Array("heading" => Array( 'type' => 'static', 'values' => "<h3>$namespace: $action</h3>" ));
  211. $plugin_fields = $header + $plugin_fields;
  212. $this->_build_form( $plugin_fields, $plugin_name );
  213. }
  214. }
  215. }
  216. }
  217. function _build_plugins_add() {
  218. $plugins = $this->_find_available_plugins();
  219. $i = 0;
  220. foreach ( $plugins as $namespace => $actions ) {
  221. $plugin_add_namespaces[$i] = $namespace;
  222. $plugin_add_actions[$i] = array_keys( $actions );
  223. $i++;
  224. }
  225. $this->_build_form( Array("plugin_add_notice" => Array('type' => 'static', 'values' => '<h3>Add A Plugin</h3>')));
  226. $plugin_hierselect = $this->form->addElement('hierselect', 'plugin_add', 'Add a Plugin:');
  227. $plugin_hierselect->setOptions( array($plugin_add_namespaces, $plugin_add_actions) );
  228. $add_button = $this->form->addElement( 'button', 'plugin_add_btn', null, 'onclick="addPlugin()" id="plugin_add_btn"' );
  229. $add_button->setType( 'button' );
  230. $add_button->setValue( 'Add It' );
  231. $renderer = AMP_get_renderer( );
  232. $this->form->addElement( 'static', 'reminder', '',$renderer->span( AMP_TEXT_FORM_PLUGINS_REMINDER, array( 'class' => 'red')));
  233. }
  234. function _find_available_plugins() {
  235. $available_plugins = Array();
  236. #$udm_plugin_path_base = preg_replace( "/QuickForm/i", "", dirname( realpath( __FILE__ ) ) );
  237. $udm_plugin_path_base = AMP_BASE_INCLUDE_PATH . 'Modules/UDM/';
  238. $udm_plugin_path_local = AMP_LOCAL_PATH . '/lib/Modules/UDM/';
  239. $dh_set['base'] = opendir( $udm_plugin_path_base );
  240. $dh_set['local'] = ( file_exists( $udm_plugin_path_local ))? opendir( $udm_plugin_path_local ) : false;
  241. foreach( $dh_set as $dh_key => $dh ){
  242. while ($dh && ($namespace = readdir($dh)) !== false) {
  243. if (strpos($namespace, ".") === 0) continue;
  244. $subfolder = 'udm_plugin_path_' . $dh_key;
  245. $nsdh = opendir( $$subfolder . $namespace );
  246. while (($action_file = readdir($nsdh)) !== false) {
  247. if (strpos($action_file, ".") === 0) continue;
  248. // include the file, suppress error messages, and don't let it
  249. // output anything. To my knowledge, there's no way to stop php4
  250. // from dying on fatal error, so be careful out there.
  251. ob_start();
  252. if(!include_once( "Modules/UDM/" . ucfirst($namespace) . "/" . ucfirst($action_file) )) continue;
  253. ob_end_clean();
  254. $action = preg_replace( "/\.inc\.php$/", "", $action_file );
  255. $class_vars = get_class_vars( "UserDataPlugin_" . $action . "_$namespace" );
  256. if ($class_vars['available'] != true) continue;
  257. $available_plugins[$namespace][$action] = $class_vars;
  258. }
  259. if ( isset( $available_plugins[$namespace] ) && is_array( $available_plugins[$namespace])) {
  260. ksort( $available_plugins[$namespace]);
  261. }
  262. }
  263. }
  264. ksort( $available_plugins );
  265. return $available_plugins;
  266. }
  267. function _build_preview () {
  268. $udm_copy = new UserDataInput( $this->dbcon, $this->udm->instance, true );
  269. $udm_copy->form = null;
  270. $udm_copy->showForm = true;
  271. $html = $udm_copy->output('html');
  272. preg_replace( "/<[^>]*form[^>]*>/", "", $html );
  273. $this->fields['preview'] = Array(
  274. 'tab' => Array( 'type' => 'header', 'values' => 'Preview' ),
  275. 'rendered' => Array( 'type' => 'static', 'values' => $html )
  276. );
  277. $this->_build_form( $this->fields['preview'], 'preview' );
  278. }
  279. function _build_field ( $field_name, $field ) {
  280. $fn = $field_name;
  281. $jscript = "onclick=\"changef('$fn');\"";
  282. $fa_js = "<img src=\"images/arrow-right.gif\" border=\"0\" class=\"field_arrow\" id=\"arrow_$fn\" $jscript />";
  283. $label = isset( $field['label']) ? $field[ 'label' ] : false;
  284. $flabel = ( $label ) ? "$label <span class=\"fieldname\">(<em>$fn</em>)</span>" :
  285. "Unnamed Field <span class=\"fieldname\">(<em>$fn</em>)</span>";
  286. // Do this in the absence of array_combine.
  287. $available_types = $this->form->getRegisteredTypes();
  288. foreach ( $available_types as $ftype ) {
  289. $types[ $ftype ] = $ftype;
  290. }
  291. $lookups_set = AMPSystem_Lookup::instance( 'lookups');
  292. $lookups = array( '' => AMP_TEXT_NONE_AVAILABLE );
  293. if ( $lookups_set ){
  294. $lookups = array( '' => '--' ) + $lookups_set;
  295. }
  296. #$regions = array( '' => '--' ) + $this->regions->getTLRegions();
  297. $elements = Array(
  298. "arrow_$fn" => Array( 'type' => 'static', 'values' => $fa_js ),
  299. "title_$fn" => Array( 'type' => 'static', 'values' => $flabel ),
  300. "enabled_$fn" => Array( 'type' => 'checkbox', 'values' => 'enabled' ),
  301. "public_$fn" => Array( 'type' => 'checkbox', 'values' => 'public' ),
  302. "required_$fn" => Array( 'type' => 'checkbox', 'values' => 'required' ),
  303. "type_$fn" => Array( 'type' => 'select', 'values' => $types, 'label' => 'Type' ),
  304. "label_$fn" => Array( 'type' => 'text', 'values' => null, 'label' => 'Label' ),
  305. "lookup_$fn" => Array( 'type' => 'select', 'values' => $lookups, 'label' => 'Dynamic Lookup' ),
  306. "values_$fn" => Array( 'type' => 'textarea', 'values' => null, 'label' => 'Default Values' ),
  307. "size_$fn" => Array( 'type' => 'text', 'values' => null, 'label' => 'Field Size', 'size' => 3 ),
  308. );
  309. return $elements;
  310. }
  311. }
  312. /*
  313. function udm_QuickForm_build_admin ( &$udm, $options = null ) {
  314. $frmName = $udm->name;
  315. $frmMethod = ( isset( $options['frmMethod'] ) ) ?
  316. $options['frmMethod'] : 'post';
  317. $frmAction = ( isset( $options['frmAction'] ) ) ?
  318. $options['frmAction'] : null;
  319. $form = new HTML_QuickForm( $frmName, $frmMethod, $frmAction );
  320. $form->addElement( 'hidden', 'modin', 'Module Instance' );
  321. $form->addElement( 'submit', 'btnUdmSubmit', 'Save' );
  322. /* Fetch module information.
  323. this should be moved to some generic AMP class or somesuch.
  324. *//*
  325. $modlist_rs = $udm->dbcon->CacheExecute( "SELECT moduletext.id, moduletext.name FROM moduletext, modules" .
  326. " WHERE modules.id=moduletext.modid AND " .
  327. " modules.userdatamodid=" . $udm->dbcon->qstr($udm->instance) .
  328. " ORDER BY name ASC" )
  329. or die( $udm->dbcon->ErrorMsg() );
  330. $modules[ '' ] = '--';
  331. while ( $row = $modlist_rs->FetchRow() ) {
  332. $modules[ $row['id'] ] = $row['name'];
  333. }
  334. /* Get possible sources. Again, should be moved out of here */
  335. /*
  336. $source_rs = $udm->dbcon->CacheExecute( "SELECT id, title FROM source ORDER BY title ASC" )
  337. or die( $udm->dbcon->ErrorMsg() );
  338. while ( $row = $source_rs->FetchRow() ) {
  339. $sources[ $row[ 'id' ] ] = $row[ 'title' ];
  340. }
  341. /* Yet another thing to move outta here */
  342. /*
  343. $enteredby_rs = $udm->dbcon->CacheExecute( "SELECT id, name FROM users ORDER BY name ASC" );
  344. while ( $row = $enteredby_rs->FetchRow() ) {
  345. $users[ $row['id'] ] = $row['name'];
  346. }
  347. /* Another one. */
  348. /* $MM_listtable = ( isset($GLOBALS['MM_listtable']) ) ? $GLOBALS['MM_listtable'] : 'lists';
  349. $lists_rs = $udm->dbcon->Execute( "SELECT id, name FROM $MM_listtable ORDER BY name ASC" ) or die( "Couldn't obtain list information: " . $udm->dbcon->ErrorMsg() );
  350. $lists[ '' ] = 'none';
  351. while ( $row = $lists_rs->FetchRow() ) {
  352. $lists[ $row['id'] ] = $row['name'];
  353. }
  354. $fields = $udm->fields;
  355. $fields['core_name'] = array( 'label' => 'Name', 'type' => 'text' );
  356. $fields['core_redirect'] = array( 'label' => 'Redirect URL', 'type' => 'text' );
  357. $fields['core_publish'] = array( 'label' => 'Publish Data', 'type' => 'checkbox' );
  358. $fields['core_modidinput'] = array( 'label' => 'Intro Text', 'type' => 'select', 'values' => $modules );
  359. $fields['core_modidresponse'] = array( 'label' => 'Response Text', 'type' => 'select', 'values' => $modules );
  360. $fields['core_sourceid'] = array( 'label' => 'Source', 'type' => 'select', 'values' => $sources );
  361. $fields['core_enteredby'] = array( 'label' => 'Entered By', 'type' => 'select', 'values' => $users );
  362. $fields['core_uselists'] = array( 'label' => 'Use Lists', 'type' => 'checkbox' );
  363. $fields['core_list1'] = array( 'label' => 'List #1', 'type' => 'select', 'values' => $lists );
  364. $fields['core_list2'] = array( 'label' => 'List #2', 'type' => 'select', 'values' => $lists );
  365. $fields['core_list3'] = array( 'label' => 'List #3', 'type' => 'select', 'values' => $lists );
  366. $fields['core_list4'] = array( 'label' => 'List #4', 'type' => 'select', 'values' => $lists );
  367. $fields['core_useemail'] = array( 'label' => 'Use E-Mail', 'type' => 'checkbox' );
  368. $fields['core_mailto'] = array( 'label' => 'Mail to', 'type' => 'text' );
  369. $fields['core_subject'] = array( 'label' => 'E-mail Subject', 'type' => 'text' );
  370. $fields['core_field_order'] = array( 'label' => 'Field Order', 'type' => 'textarea' );
  371. $md = $udm->_module_def;
  372. $coreFields = array( 'redirect', 'publish', 'modidinput', 'modidresponse', 'sourceid', 'enteredby', 'uselists', 'list1', 'list2', 'list3', 'list4', 'useemail', 'mailto', 'subject', 'field_order', 'name' );
  373. foreach ( $coreFields as $cf ) {
  374. $md[ 'core_' . $cf ] = $md[ $cf ];
  375. }
  376. /* $fSep = array( "</td><td>", // down arrow -> field name
  377. "</td><td>", // field name -> enabled
  378. "</td><td>", // enabled -> public
  379. "</td><td>", // public -> required
  380. "</td></tr><tr><td colspan=\"5\">", // required -> hidden stuff, type
  381. "</td><td colspan=\"2\">", // type -> label
  382. "</td></tr><tr><td>", // label -> region
  383. "</td><td>", // region -> default values
  384. "</td><td>", // default values -> field size
  385. "</td></tr></table></div></td></tr></table>\n\n", // field size -> end of row
  386. ); */
  387. /* $fSep = '';
  388. $panels = array( 'core', 'standard', 'custom', 'plugins', 'preview' );
  389. /* foreach ( $panels as $panel ) {
  390. $renderer->setGroupTemplate("\n\n<div id=\"udm_$panel\" style=\"display: none;\">{content}</div>", $panel);
  391. $renderer->setGroupElementTemplate( "{label}&nbsp;{element}\n", $panel );
  392. $renderer->setElementTemplate("{label}&nbsp;{element}</div>", $panel);
  393. } */
  394. /*
  395. $form->addGroup( array(), 'core', null, '&nbsp;', false );
  396. $form->addGroup( array(), 'standard', null, $fSep, false );
  397. $form->addGroup( array(), 'custom', null, $fSep, false );
  398. $form->addGroup( array(), 'plugins', null, '&nbsp;', false );
  399. $form->addGroup( array(), 'preview', null, '&nbsp;', false );
  400. /*
  401. $renderer = $form->defaultRenderer();
  402. $renderer->setGroupTemplate( "\n</td></tr></table><div id=\"udm_core\"><table width=\"100%\" class=\"name\">{content}</table></div><table width=\"100%\" class=\"name\"><tr><td>\n", 'core' );
  403. $renderer->setGroupTemplate( "\n</td></tr></table>\n\n<br clear=\"all\">\n<div id=\"udm_standard\" style=\"display: none\"><!-- begin standard content --><table width=\"100%\" class=\"name\"><tr><td>{content}</td></tr></table></div></td></tr></table></div>\n<table width=\"100%\" class=\"name\"><tr><td width=\"12\">", 'standard' );
  404. $renderer->setGroupTemplate( "\n</td></tr></table>\n\n<br clear=\"all\">\n<div id=\"udm_custom\" style=\"display: none\"><table width=\"100%\" class=\"name\"><tr><td width=\"12\">{content}</td></tr></table></div></td></tr></table></div>\n<table width=\"100%\" class=\"name\"><tr><td>", 'custom' );
  405. $renderer->setGroupTemplate( "\n</td></tr></table>\n\n<br clear=\"all\">\n<div id=\"udm_plugins\" style=\"display: none\"><table width=\"100%\" class=\"name\"><tr><td>{content}</td></tr></table></div></td></tr></table></div>\n<table width=\"100%\" class=\"name\"><tr><td>", 'plugins' );
  406. $renderer->setGroupTemplate( "\n</td></tr></table>\n\n<br clear=\"all\">\n<div id=\"udm_preiew\" style=\"display: none\"><table width=\"100%\" class=\"name\"><tr><td>{content}</td></tr></table></div></td></tr></table></div>\n<table width=\"100%\" class=\"name\"><tr><td>", 'preview' );
  407. $renderer->setGroupElementTemplate( "<tr><td>{label}</td><td>{element}</td></tr>\n", 'core' );
  408. $renderer->setGroupElementTemplate( "<tr><td>{label}</td><td>{element}</td></tr>\n", 'plugins' );
  409. $renderer->setGroupElementTemplate( "{label}&nbsp;{element}\n", 'standard' );
  410. $renderer->setGroupElementTemplate( "{label}&nbsp;{element}\n", 'preview' );
  411. $renderer->setGroupElementTemplate( "{label}&nbsp;{element}\n", 'custom' );
  412. */
  413. /*
  414. foreach ( $udm->fields as $field => $field_def ) {
  415. udm_QuickForm_build_admin_addElement( $form, $field, $field_def );
  416. }
  417. $preview = $form->getElement('preview');
  418. $pr_elem = $preview->getElements();
  419. $plugin_gr = $form->getElement('plugins');
  420. $pl_elem = $plugin_gr->getElements();
  421. $plugins = $udm->getPlugins();
  422. udm_quickform_build_admin_plugins( $plugins, $pl_elem );
  423. ob_start();
  424. $plug_view = array();
  425. foreach ($plugins as $plugin => $namespace) {
  426. foreach ($namespace as $ns => $pl) {
  427. $plug_view[$ns][$plugin] = $pl->options;
  428. }
  429. }
  430. print_r($pl_elem);
  431. $pl_raw = ob_get_contents();
  432. ob_end_clean();
  433. $tmpUdm = $udm;
  434. $tmpUdm->form = null;
  435. $tmpUdm->showForm = true;
  436. ob_start();
  437. $tmpUdm->output('html');
  438. $preview_html = ob_get_contents();
  439. ob_end_clean();
  440. $pr_elem[] = &HTML_QuickForm::createElement( 'html', $preview_html );
  441. $form->setDefaults( $md );
  442. $form->setConstants( array( 'modin' => $udm->instance ) );
  443. $tpl = new Smarty;
  444. $tpl->template_dir = $_SERVER['DOCUMENT_ROOT'] . '/include/templates/UserData';
  445. $tpl->compile_dir = AMP_LOCAL_PATH . '/cache';
  446. $tpl->assign('static', $pl_raw);
  447. $renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl, true);
  448. $renderer->setTemplate('admin.tpl');
  449. $form->accept($renderer);
  450. if ( !isset( $options[ 'no_validate' ] ) ) {
  451. if ( !$form->validate() ) {
  452. $udm->form = $form;
  453. return false;
  454. }
  455. }
  456. $udm->form = $form;
  457. return $form;
  458. }
  459. function udm_QuickForm_build_admin_plugins ( $plugins, &$elements ) {
  460. foreach ( $plugins as $action => $plugin ) {
  461. $elements[] = &HTML_QuickForm::createElement( 'static', $action );
  462. foreach ( $plugin as $namespace => $plugin_obj ) {
  463. if (!$plugin_obj->available ) continue;
  464. $elements[] = &HTML_QuickForm::createElement( 'static', $namespace );
  465. udm_QuickForm_build_admin_plugins_options( $namespace, $plugin, $elements );
  466. }
  467. }
  468. }
  469. function udm_QuickForm_build_admin_plugins_options( $namespace, $plugin, &$elements ) {
  470. foreach ( $plugin['options'] as $option => $option_def ) {
  471. print "I'm doing something here....";
  472. $element = &HTML_QuickForm::createElement( $option_def['type'],
  473. $namespace . $plugin['short_name'] . $option,
  474. $option_def['description'],
  475. $option_def['default'] );
  476. if ( isset($option_def['size']) ) $element->setSize( $option_def['size'] );
  477. $elements[] = $element;
  478. }
  479. }
  480. function udm_QuickForm_build_admin_addElement( &$form, $name, $field_def ) {
  481. if ( $name == '' ) return;
  482. $type = $field_def[ 'type' ];
  483. $label = $field_def[ 'label' ];
  484. $defaults = ( isset($field_def['values']) ) ? $field_def[ 'values' ] : null;
  485. foreach ( array_values( $form->getRegisteredTypes() ) as $ftype ) {
  486. $types[ $ftype ] = $ftype;
  487. }
  488. $types[ 'HTML_QuickForm_select' ] = 'HTML_QuickForm_select';
  489. if ( substr( $name, 0, 6 ) == "custom" ) {
  490. $groupName = "custom";
  491. } elseif ( substr( $name, 0, 4 ) == "core" ) {
  492. $groupName = "core";
  493. } else {
  494. $groupName = "standard";
  495. }
  496. $group = $form->getElement( $groupName );
  497. $elements = $group->getElements();
  498. $jscript = "onclick=\"changef('$name');\"";
  499. $regions = array( '' => '--' ) + $GLOBALS['regionObj']->getTLRegions();
  500. if ( $groupName != "core" ) {
  501. $elements[] = &HTML_QuickForm::createElement( 'static', 'arrow_' . $name, null, '<img src="images/arrow-right.gif" border="0" class="field_arrow" id="arrow_' . $name . "\" $jscript />" );
  502. $elements[] = &HTML_QuickForm::createElement( 'static', 'title_' . $name, null, ( $label ) ? $label . " <span class=\"fieldname\">(<em>$name</em>)</span>" : 'Unnamed Field' . " <span class=\"fieldname\">(<em>$name</em>)</span>" );
  503. $elements[] = &HTML_QuickForm::createElement( 'checkbox', 'enabled_' . $name, null, 'enabled' );
  504. $elements[] = &HTML_QuickForm::createElement( 'checkbox', 'public_' . $name, null, 'public' );
  505. $elements[] = &HTML_QuickForm::createElement( 'checkbox', 'required_' . $name, null, 'required' );
  506. $elements[] = &HTML_QuickForm::createElement( 'select', 'type_' . $name, 'Type', $types );
  507. $elements[] = &HTML_QuickForm::createElement( 'text', 'label_' . $name, 'Label' );
  508. $elements[] = &HTML_QuickForm::createElement( 'select', 'region_' . $name, 'Region', $regions);
  509. $elements[] = &HTML_QuickForm::createElement( 'textarea', 'values_' . $name, 'Default Values' );
  510. $fieldSize = &HTML_QuickForm::createElement( 'text', 'size_' . $name, 'Field Size' );
  511. $fieldSize->setSize( '3' );
  512. $elements[] = $fieldSize;
  513. } else {
  514. $elements[] = &HTML_QuickForm::createElement( $type, $name, $label, $defaults );
  515. }
  516. return 1;
  517. }
  518. */
  519. ?>