|
From: Verdon V. <ve...@us...> - 2008-06-11 17:44:08
|
Update of /cvsroot/phpwebsite-comm/modules/rolodex/class In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8749/class Modified Files: RDX_Forms.php RDX_Member.php Rolodex.php Log Message: adding locations and features Index: RDX_Forms.php =================================================================== RCS file: /cvsroot/phpwebsite-comm/modules/rolodex/class/RDX_Forms.php,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** RDX_Forms.php 10 Jun 2008 17:15:12 -0000 1.8 --- RDX_Forms.php 11 Jun 2008 17:43:32 -0000 1.9 *************** *** 68,71 **** --- 68,87 ---- break; + case 'edit_location': + if (empty($this->rolodex->location)) { + $this->rolodex->loadLocation(); + } + $this->rolodex->panel->setCurrentTab('locations'); + $this->editLocation(); + break; + + case 'edit_feature': + if (empty($this->rolodex->feature)) { + $this->rolodex->loadFeature(); + } + $this->rolodex->panel->setCurrentTab('features'); + $this->editFeature(); + break; + case 'list': $this->rolodex->panel->setCurrentTab('list'); *************** *** 93,96 **** --- 109,122 ---- break; + case 'locations': + $this->rolodex->panel->setCurrentTab('locations'); + $this->listLocations(); + break; + + case 'features': + $this->rolodex->panel->setCurrentTab('features'); + $this->listFeatures(); + break; + case 'info': $this->rolodex->panel->setCurrentTab('info'); *************** *** 226,229 **** --- 252,327 ---- + function listLocations() + { + $ptags['TITLE_HEADER'] = dgettext('rolodex', 'Title'); + $ptags['DESCRIPTION_HEADER'] = dgettext('rolodex', 'Description'); + + PHPWS_Core::initModClass('rolodex', 'RDX_Location.php'); + PHPWS_Core::initCoreClass('DBPager.php'); + $pager = new DBPager('rolodex_location', 'Rolodex_Location'); + $pager->setModule('rolodex'); + $pager->setOrder('title', 'asc', true); + $pager->setTemplate('list_location.tpl'); + $pager->addRowTags('rowTag'); + $num = $pager->getTotalRows(); + if ($num == '0') { + if (Current_User::allow('rolodex', 'settings')) { + $vars['aop'] = 'menu'; + $vars['tab'] = 'settings'; + $vars2['aop'] = 'new_location'; + $ptags['EMPTY_MESSAGE'] = sprintf(dgettext('rolodex', 'Check your %s then create a %s to begin'), PHPWS_Text::secureLink(dgettext('rolodex', 'Settings'), 'rolodex', $vars), PHPWS_Text::secureLink(dgettext('rolodex', 'New Location'), 'rolodex', $vars2)); + } else { + $ptags['EMPTY_MESSAGE'] = dgettext('rolodex', 'Sorry, no locations are available at this time.'); + } + } + if (Current_User::allow('rolodex', 'settings')) { + $vars['aop'] = 'new_location'; + $ptags['ADD_LINK'] = PHPWS_Text::secureLink(dgettext('rolodex', 'Add Location'), 'rolodex', $vars); + } + $pager->addPageTags($ptags); + $pager->addToggle('class="toggle1"'); + $pager->setSearch('title', 'description'); + + $this->rolodex->content = $pager->get(); + $this->rolodex->title = sprintf(dgettext('rolodex', '%s Locations'), PHPWS_Settings::get('rolodex', 'module_title')); + } + + + function listFeatures() + { + $ptags['TITLE_HEADER'] = dgettext('rolodex', 'Title'); + $ptags['DESCRIPTION_HEADER'] = dgettext('rolodex', 'Description'); + + PHPWS_Core::initModClass('rolodex', 'RDX_Feature.php'); + PHPWS_Core::initCoreClass('DBPager.php'); + $pager = new DBPager('rolodex_feature', 'Rolodex_feature'); + $pager->setModule('rolodex'); + $pager->setOrder('title', 'asc', true); + $pager->setTemplate('list_feature.tpl'); + $pager->addRowTags('rowTag'); + $num = $pager->getTotalRows(); + if ($num == '0') { + if (Current_User::allow('rolodex', 'settings')) { + $vars['aop'] = 'menu'; + $vars['tab'] = 'settings'; + $vars2['aop'] = 'new_feature'; + $ptags['EMPTY_MESSAGE'] = sprintf(dgettext('rolodex', 'Check your %s then create a %s to begin'), PHPWS_Text::secureLink(dgettext('rolodex', 'Settings'), 'rolodex', $vars), PHPWS_Text::secureLink(dgettext('rolodex', 'New Feature'), 'rolodex', $vars2)); + } else { + $ptags['EMPTY_MESSAGE'] = dgettext('rolodex', 'Sorry, no features are available at this time.'); + } + } + if (Current_User::allow('rolodex', 'settings')) { + $vars['aop'] = 'new_feature'; + $ptags['ADD_LINK'] = PHPWS_Text::secureLink(dgettext('rolodex', 'Add Feature'), 'rolodex', $vars); + } + $pager->addPageTags($ptags); + $pager->addToggle('class="toggle1"'); + $pager->setSearch('title', 'description'); + + $this->rolodex->content = $pager->get(); + $this->rolodex->title = sprintf(dgettext('rolodex', '%s Features'), PHPWS_Settings::get('rolodex', 'module_title')); + } + + function editSettings() { *************** *** 325,328 **** --- 423,434 ---- $form->setSize('max_thumb_height', 4,4); + $form->addTextField('other_img_width', PHPWS_Settings::get('rolodex', 'other_img_width')); + $form->setLabel('other_img_width', dgettext('rolodex', 'Maximum image width for locations/features (20-400)')); + $form->setSize('other_img_width', 4,4); + + $form->addTextField('other_img_height', PHPWS_Settings::get('rolodex', 'other_img_height')); + $form->setLabel('other_img_height', dgettext('rolodex', 'Maximum image height for locations/features (20-400)')); + $form->setSize('other_img_height', 4,4); + $form->addCheckbox('show_block', 1); $form->setMatch('show_block', PHPWS_Settings::get('rolodex', 'show_block')); *************** *** 674,677 **** --- 780,788 ---- $tpl['CATEGORIES'] = Categories::getForm($match=$member->get_categories(), $select_name='categories', $multiple=true); + $tpl['LOCATIONS'] = $this->rolodex->getForm('location', $match=$member->get_locations(), $select_name='locations', $multiple=true); + $tpl['FEATURES'] = $this->rolodex->getForm('feature', $match=$member->get_features(), $select_name='features', $multiple=true); + $tpl['CATEGORIES_LABEL'] = dgettext('rolodex', 'Category(s)'); + $tpl['LOCATIONS_LABEL'] = dgettext('rolodex', 'Location(s)'); + $tpl['FEATURES_LABEL'] = dgettext('rolodex', 'Feature(s)'); if (Current_User::allow('rolodex', 'edit_member')) { *************** *** 696,699 **** --- 807,898 ---- + function editLocation() + { + $form = new PHPWS_Form('rolodex_location'); + $location = & $this->rolodex->location; + + $form->addHidden('module', 'rolodex'); + $form->addHidden('aop', 'post_location'); + + if ($location->id) { + $form->addHidden('id', $location->id); + $form->addSubmit(dgettext('rolodex', 'Update')); + $this->rolodex->title = sprintf(dgettext('rolodex', 'Update %s location'), PHPWS_Settings::get('rolodex', 'module_title')); + } else { + $form->addSubmit(dgettext('rolodex', 'Create')); + $this->rolodex->title = sprintf(dgettext('rolodex', 'Create %s location'), PHPWS_Settings::get('rolodex', 'module_title')); + } + + $form->addText('title', $location->title); + $form->setSize('title', 40); + $form->setLabel('title', dgettext('rolodex', 'Title')); + + $form->addTextArea('description', $location->description); + $form->setRows('description', '6'); + $form->setCols('description', '40'); + $form->setLabel('description', dgettext('rolodex', 'Description')); + + PHPWS_Core::initModClass('filecabinet', 'Cabinet.php'); + $manager = Cabinet::fileManager('image_id', $location->image_id); + $manager->imageOnly(); + $manager->maxImageWidth(PHPWS_Settings::get('rolodex', 'other_img_width')); + $manager->maxImageHeight(PHPWS_Settings::get('rolodex', 'other_img_height')); + + if ($manager) { + $form->addTplTag('FILE_MANAGER', $manager->get()); + } + + $tpl = $form->getTemplate(); + $tpl['DETAILS_LABEL'] = dgettext('rolodex', 'Details'); + + $this->rolodex->content = PHPWS_Template::process($tpl, 'rolodex', 'edit_location.tpl'); + + } + + + function editFeature() + { + $form = new PHPWS_Form('rolodex_feature'); + $feature = & $this->rolodex->feature; + + $form->addHidden('module', 'rolodex'); + $form->addHidden('aop', 'post_feature'); + + if ($feature->id) { + $form->addHidden('id', $feature->id); + $form->addSubmit(dgettext('rolodex', 'Update')); + $this->rolodex->title = sprintf(dgettext('rolodex', 'Update %s feature'), PHPWS_Settings::get('rolodex', 'module_title')); + } else { + $form->addSubmit(dgettext('rolodex', 'Create')); + $this->rolodex->title = sprintf(dgettext('rolodex', 'Create %s feature'), PHPWS_Settings::get('rolodex', 'module_title')); + } + + $form->addText('title', $feature->title); + $form->setSize('title', 40); + $form->setLabel('title', dgettext('rolodex', 'Title')); + + $form->addTextArea('description', $feature->description); + $form->setRows('description', '6'); + $form->setCols('description', '40'); + $form->setLabel('description', dgettext('rolodex', 'Description')); + + PHPWS_Core::initModClass('filecabinet', 'Cabinet.php'); + $manager = Cabinet::fileManager('image_id', $feature->image_id); + $manager->imageOnly(); + $manager->maxImageWidth(PHPWS_Settings::get('rolodex', 'other_img_width')); + $manager->maxImageHeight(PHPWS_Settings::get('rolodex', 'other_img_height')); + + if ($manager) { + $form->addTplTag('FILE_MANAGER', $manager->get()); + } + + $tpl = $form->getTemplate(); + $tpl['DETAILS_LABEL'] = dgettext('rolodex', 'Details'); + + $this->rolodex->content = PHPWS_Template::process($tpl, 'rolodex', 'edit_feature.tpl'); + + } + + function utilities() { Index: Rolodex.php =================================================================== RCS file: /cvsroot/phpwebsite-comm/modules/rolodex/class/Rolodex.php,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Rolodex.php 10 Jun 2008 17:15:12 -0000 1.6 --- Rolodex.php 11 Jun 2008 17:43:32 -0000 1.7 *************** *** 92,100 **** $this->forwardMessage(dgettext('rolodex', 'Error occurred when saving member profile.')); PHPWS_Core::reroute('index.php?module=rolodex&aop=edit_member&user_id=' . $this->member->user_id); - // PHPWS_Core::reroute('index.php?module=rolodex&aop=menu&tab=list'); } else { $this->forwardMessage(dgettext('rolodex', 'Member profile saved successfully.')); - // PHPWS_Core::reroute('index.php?module=rolodex&aop=edit_member&user_id=' . $this->member->user_id); - // PHPWS_Core::reroute('index.php?module=rolodex&aop=menu&tab=list'); PHPWS_Core::reroute('index.php?module=rolodex&id=' . $this->member->user_id); } --- 92,97 ---- *************** *** 196,199 **** --- 193,248 ---- break; + case 'new_location': + case 'edit_location': + $this->loadForm('edit_location'); + break; + + case 'post_location': + if ($this->postLocation()) { + if (PHPWS_Error::logIfError($this->location->save())) { + $this->forwardMessage(dgettext('rolodex', 'Error occurred when saving location.')); + PHPWS_Core::reroute('index.php?module=rolodex&aop=edit_location&location=' . $this->location->id); + } else { + $this->forwardMessage(dgettext('rolodex', 'Location saved successfully.')); + PHPWS_Core::reroute('index.php?module=rolodex&aop=menu&tab=locations'); + } + } else { + $this->loadForm('edit_location'); + } + break; + + case 'delete_location': + $this->loadLocation(); + $this->location->delete(); + $this->message = dgettext('rolodex', 'Location deleted.'); + $this->loadForm('list'); + break; + + case 'new_feature': + case 'edit_feature': + $this->loadForm('edit_feature'); + break; + + case 'post_feature': + if ($this->postFeature()) { + if (PHPWS_Error::logIfError($this->feature->save())) { + $this->forwardMessage(dgettext('rolodex', 'Error occurred when saving feature.')); + PHPWS_Core::reroute('index.php?module=rolodex&aop=edit_feature&feature=' . $this->feature->id); + } else { + $this->forwardMessage(dgettext('rolodex', 'Feature saved successfully.')); + PHPWS_Core::reroute('index.php?module=rolodex&aop=menu&tab=features'); + } + } else { + $this->loadForm('edit_feature'); + } + break; + + case 'delete_feature': + $this->loadFeature(); + $this->feature->delete(); + $this->message = dgettext('rolodex', 'Feature deleted.'); + $this->loadForm('list'); + break; + } *************** *** 342,346 **** } PHPWS_Core::reroute('index.php?module=rolodex&uop=edit_member&user_id=' . $this->member->user_id); - // PHPWS_Core::reroute('index.php?module=rolodex&uop=list'); } else { if (PHPWS_Settings::get('rolodex', 'req_approval') && $this->member->isNew()) { --- 391,394 ---- *************** *** 357,360 **** --- 405,420 ---- break; + case 'view_location': + $this->loadLocation(); + $this->title = $this->location->getTitle(); + $this->content = $this->location->view(); + break; + + case 'view_feature': + $this->loadFeature(); + $this->title = $this->feature->getTitle(); + $this->content = $this->feature->view(); + break; + *************** *** 399,402 **** --- 459,494 ---- + function loadLocation($id=0) + { + PHPWS_Core::initModClass('rolodex', 'RDX_Location.php'); + + if ($id) { + $this->location = new Rolodex_Location($id); + } elseif (isset($_REQUEST['location_id'])) { + $this->location = new Rolodex_Location($_REQUEST['location_id']); + } elseif (isset($_REQUEST['location'])) { + $this->location = new Rolodex_Location($_REQUEST['location']); + } else { + $this->location = new Rolodex_Location; + } + } + + + function loadFeature($id=0) + { + PHPWS_Core::initModClass('rolodex', 'RDX_Feature.php'); + + if ($id) { + $this->feature = new Rolodex_Feature($id); + } elseif (isset($_REQUEST['feature_id'])) { + $this->feature = new Rolodex_Feature($_REQUEST['feature_id']); + } elseif (isset($_REQUEST['feature'])) { + $this->feature = new Rolodex_Feature($_REQUEST['feature']); + } else { + $this->feature = new Rolodex_Feature; + } + } + + function loadPanel() { *************** *** 430,433 **** --- 522,529 ---- 'link'=>$link); } + $tags['locations'] = array('title'=>dgettext('rolodex', 'Locations'), + 'link'=>$link); + $tags['features'] = array('title'=>dgettext('rolodex', 'Features'), + 'link'=>$link); if (Current_User::allow('rolodex', 'edit_member')){ $tags['info'] = array('title'=>dgettext('rolodex', 'Read me'), *************** *** 544,547 **** --- 640,657 ---- } + if ( !empty($_POST['other_img_width']) ) { + $other_img_width = (int)$_POST['other_img_width']; + if ($other_img_width >= 20 && $other_img_width <= 400 ) { + PHPWS_Settings::set('rolodex', 'other_img_width', $other_img_width); + } + } + + if ( !empty($_POST['other_img_height']) ) { + $other_img_height = (int)$_POST['other_img_height']; + if ($other_img_height >= 20 && $other_img_height <= 400 ) { + PHPWS_Settings::set('rolodex', 'other_img_height', $other_img_height); + } + } + isset($_POST['show_block']) ? PHPWS_Settings::set('rolodex', 'show_block', 1) : *************** *** 874,877 **** --- 984,1047 ---- + function postLocation() + { + $this->loadLocation(); + + if (empty($_POST['title'])) { + $errors[] = dgettext('rolodex', 'You must give this location a title.'); + } else { + $this->location->setTitle($_POST['title']); + } + + if (empty($_POST['description'])) { + $errors[] = dgettext('rolodex', 'You must give this location a description.'); + } else { + $this->location->setDescription($_POST['description']); + } + + if (isset($_POST['image_id'])) { + $this->location->setImage_id((int)$_POST['image_id']); + } + + if (isset($errors)) { + $this->message = implode('<br />', $errors); + return false; + } else { + return true; + } + + } + + + function postFeature() + { + $this->loadFeature(); + + if (empty($_POST['title'])) { + $errors[] = dgettext('rolodex', 'You must give this feature a title.'); + } else { + $this->feature->setTitle($_POST['title']); + } + + if (empty($_POST['description'])) { + $errors[] = dgettext('rolodex', 'You must give this feature a description.'); + } else { + $this->feature->setDescription($_POST['description']); + } + + if (isset($_POST['image_id'])) { + $this->feature->setImage_id((int)$_POST['image_id']); + } + + if (isset($errors)) { + $this->message = implode('<br />', $errors); + return false; + } else { + return true; + } + + } + + function resetExpired($interval) { *************** *** 1118,1121 **** --- 1288,1348 ---- + /** + * Returns a form for module inclusion + * @author Matthew McNaney <ma...@NO...> + * @modified Verdon Vaillancourt + * @access public + */ + function getForm($type='location', $match=null, $select_name='location', $multiple=true) + { + + switch($type) { + case 'location': + PHPWS_Core::initModClass('rolodex', 'RDX_Location.php'); + $db = new PHPWS_DB('rolodex_location'); + $db->addOrder('title asc'); + $result = $db->getObjects('Rolodex_Location'); + break; + case 'feature': + PHPWS_Core::initModClass('rolodex', 'RDX_Feature.php'); + $db = new PHPWS_DB('rolodex_feature'); + $db->addOrder('title asc'); + $result = $db->getObjects('Rolodex_Feature'); + break; + } + + foreach ($result as $item) { + $items[$item->id] = $item->title; + } + + if ($multiple) { + if (javascriptEnabled()) { + $vars['id'] = 'cid-' . rand(); + $vars['select_name'] = $select_name; + $vars['options'] = $items; + if (!empty($match) && is_array($match)) { + $vars['match'] = $match; + } + return javascript('multiple_select', $vars); + } else { + $form = new PHPWS_Form; + $form->addMultiple($select_name, $items); + if (!empty($match) && is_array($match)) { + $form->setMatch($select_name, $match); + } + return $form->get($select_name); + } + } else { + $form = new PHPWS_Form; + $form->addSelect($select_name, $items); + if (!empty($match) && is_string($match)) { + $form->setMatch($select_name, $match); + } + return $form->get($select_name); + } + + } + + Index: RDX_Member.php =================================================================== RCS file: /cvsroot/phpwebsite-comm/modules/rolodex/class/RDX_Member.php,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RDX_Member.php 10 Jun 2008 17:15:12 -0000 1.5 --- RDX_Member.php 11 Jun 2008 17:43:32 -0000 1.6 *************** *** 115,118 **** --- 115,138 ---- } + function get_locations($print=false) + { + if ($print) { + $result = 'code this'; + } else { + $result = unserialize($this->locations); + } + return $result; + } + + function get_features($print=false) + { + if ($print) { + $result = 'code this'; + } else { + $result = unserialize($this->features); + } + return $result; + } + function setAvatar($avatar_url) { *************** *** 1433,1436 **** --- 1453,1464 ---- } + if (isset($_POST['locations'])) { + } else { + } + + if (isset($_POST['features'])) { + } else { + } + return $this->save(); } |