registerTask( 'add' , 'edit' ); $this->registerTask( 'accesspublic', 'accessMenu'); $this->registerTask( 'accessregistered', 'accessMenu'); $this->registerTask( 'accessspecial', 'accessMenu'); $this->registerTask( 'exportxml', 'exportXML'); $this->registerTask( 'importxml', 'importXML'); } /** * display the edit form * @return void */ function edit() { $thismodel = $this->getModel( 'sqlexcelschedule' ); $thismodel->checkout(); JRequest::setVar( 'view', 'sqlexcelschedule' ); JRequest::setVar( 'layout', 'form' ); JRequest::setVar('hidemainmenu', 1); parent::display(); } /** * Move Section Up * @return void */ function orderup() { $model = $this->getModel( 'sqlexcelschedule' ); $model->move(-1); $link = 'index.php?option=com_sql2excel&view=sqlexcelschedules'; $this->setRedirect( $link ); } /** * Move Section Down * @return void */ function orderdown() { $model = $this->getModel( 'sqlexcelschedule' ); $model->move(1); $link = 'index.php?option=com_sql2excel&view=sqlexcelschedules'; $this->setRedirect( $link ); } /** * Apply changes to the record * @return void */ function apply() { $this->save(); } /** * Save a record * @return void */ function save() { $post = JRequest::get('post'); $action = $post['action']; if ( $action == 30 || $action == 40 ) { // Email if ( $post['html'] == 1 ) { $post['email_body'] = JRequest::getVar( 'email_body_html', '', 'post', 'string', JREQUEST_ALLOWRAW ); } else { $post['email_body'] = JRequest::getVar( 'email_body_text', '', 'post', 'string', JREQUEST_ALLOWRAW ); } } elseif ( $action == 50 ) { // Fix reversed SQL $sdata = $this->utf8_strrev(JRequest::getVar( 'sdata_sql', '', 'post', 'string', JREQUEST_ALLOWRAW )); $sdata = str_replace("@~@","\n", $sdata); $post['sdata'] = $sdata; //$post['sdata'] = JRequest::getVar( 'sdata_sql', '', 'post', 'string', JREQUEST_ALLOWRAW ); } elseif ( $action == 60 ) { $post['sdata'] = JRequest::getVar( 'sdata_php', '', 'post', 'string', JREQUEST_ALLOWRAW ); } // Fix reversed SQL - run_if_sql $run_if_sql = $this->utf8_strrev(JRequest::getVar( 'run_if_sql', '', 'post', 'string', JREQUEST_ALLOWRAW )); $run_if_sql = str_replace("@~@","\n", $run_if_sql); $post['run_if_sql'] = $run_if_sql; // Fix reversed SQL - on_success_sql $on_success_sql = $this->utf8_strrev(JRequest::getVar( 'on_success_sql', '', 'post', 'string', JREQUEST_ALLOWRAW )); $on_success_sql = str_replace("@~@","\n", $on_success_sql); $post['on_success_sql'] = $on_success_sql; // Fix reversed SQL - on_failure_sql $on_failure_sql = $this->utf8_strrev(JRequest::getVar( 'on_failure_sql', '', 'post', 'string', JREQUEST_ALLOWRAW )); $on_failure_sql = str_replace("@~@","\n", $on_failure_sql); $post['on_failure_sql'] = $on_failure_sql; $cid = JRequest::getVar( 'cid', array(0), 'post', 'array' ); $post['id'] = (int) $cid[0]; // 0 for new, or actual ID when editing $model = $this->getModel('sqlexcelschedule'); if ( $post['id'] == 0 || $post['id'] == null || $post['id'] == '' || $post['created'] == '' ) { $post['created'] = date('Y-m-d H:i:s'); } $task = JRequest::getCmd('task'); $workbooks = $post['workbooks']; if ( $task == 'apply' ) { $id = $model->store($post); if ($id && $id > 0) { $model->storeWB($id, $workbooks); if ( (int) $cid[0] > 0 ) { $msg = JText::_( 'Schedule Changes Saved' ); } else { $msg = JText::_( 'New schedule Saved' ); } } else { $msg = JText::_( 'Error Saving schedule' ); } $this->setRedirect( 'index.php?option=com_sql2excel&controller=sqlexcelschedule&task=edit&cid[]=' . $id, $msg ); } else { $id = $model->store($post); if ( $id ) { $model->storeWB($id, $workbooks); if ( (int) $cid[0] > 0 ) { $msg = JText::_( 'Schedule Changes Saved' ); } else { $msg = JText::_( 'New schedule Saved' ); } } else { if ( (int) $cid[0] > 0 ) { $msg = JText::_( 'Error Saving schedule Changes' ); } else { $msg = JText::_( 'Error Saving New schedule' ); } } $this->setRedirect( 'index.php?option=com_sql2excel&view=sqlexcelschedules', $msg ); } } function utf8_strrev($str, $reverse_numbers = true){ $pattern = $reverse_numbers ? '/./us' : '/(\d+)?./us'; preg_match_all($pattern, $str, $ar); return join('',array_reverse($ar[0])); } /** * Save Ordering of Categories * @return void */ function saveorder() { $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); $order = JRequest::getVar( 'order', array(), 'post', 'array' ); JArrayHelper::toInteger($cid); JArrayHelper::toInteger($order); $model = $this->getModel( 'sqlexcelschedule' ); $model->saveorder($cid, $order); $msg = JText::_( 'New schedule order saved' ); $link = 'index.php?option=com_sql2excel&view=sqlexcelschedules'; $this->setRedirect( $link, $msg ); } /** * remove record(s) * @return void */ function remove() { $model = $this->getModel('sqlexcelschedule'); if(!$model->delete()) { $msg = JText::_( 'Error: One or More Categories Could not be Deleted' ); } else { $msg = JText::_( 'Schedule(s) Deleted' ); } $this->setRedirect( 'index.php?option=com_sql2excel&view=sqlexcelschedules', $msg ); } /** * Method to copy schedule(s) * * @access public * @return boolean True on success */ function copy() { global $mainframe; $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); JArrayHelper::toInteger($cid); if (count( $cid ) < 1) { JError::raiseError(500, JText::_('Please select a Worksheet to Copy' ) ); } $model = $this->getModel('sqlexcelschedule'); //if(!$model->copy($cid)) { // echo "\n"; //} else { // $msg = count( $cid ) . ' ' . JText::_('schedule(s) Copied!'); //} $msg = $model->copy($cid); $this->setRedirect( 'index.php?option=com_sql2excel&view=sqlexcelschedules', $msg ); } /** * Method to publish schedule(s) * * @access public * @return boolean True on success */ function publish() { global $mainframe; $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); JArrayHelper::toInteger($cid); if (count( $cid ) < 1) { JError::raiseError(500, JText::_( 'Please select a schedule to publish' ) ); } $model = $this->getModel('sqlexcelschedule'); if(!$model->publish($cid, 1)) { echo "\n"; } else { $model->checkin(); } $link = 'index.php?option=com_sql2excel&view=sqlexcelschedules'; $this->setRedirect($link); } function unpublish() { global $mainframe; $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); JArrayHelper::toInteger($cid); if (count( $cid ) < 1) { JError::raiseError(500, JText::_( 'Select a schedule to unpublish' ) ); } $model = $this->getModel('sqlexcelschedule'); if(!$model->publish($cid, 0)) { echo "\n"; } else { $model->checkin(); } $link = 'index.php?option=com_sql2excel&view=sqlexcelschedules'; $this->setRedirect($link); } function accessMenu() { $post = JRequest::get('post'); $cid = JRequest::getVar( 'cid', array(0), 'post', 'array' ); $access = $post['task']; switch ($access) { case 'accessregistered': $access_id= 1; break; case 'accessspecial': $access_id= 2; break; case 'accesspublic': default: $access_id= 0; break; } $model = $this->getModel( 'sqlexcelschedule' ); $model->accessmenu($cid[0],$access_id); $model->checkin(); $link = 'index.php?option=com_sql2excel&view=sqlexcelschedules'; $this->setRedirect($link); } /** * cancel editing a record * @return void */ function cancel() { $msg = JText::_( 'Operation Cancelled' ); $this->setRedirect( 'index.php?option=com_sql2excel&view=sqlexcelschedules', $msg ); } /** * Export schedule(s) to XML file * @return void */ function exportXML() { $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); JArrayHelper::toInteger($cid); if (count( $cid ) < 1) { JError::raiseError(500, JText::_( 'Please select a schedule to export' ) ); } $model = $this->getModel('sqlexcelschedule'); if($model->exportXML($cid) ) { // XML file feed to the browser by the model exit; } else { echo "\n"; $link = 'index.php?option=com_sql2excel&view=sqlexcelschedules'; $this->setRedirect( $link, 'EXPORT XML FAILED' ); } } /** * Import schedule(s) from XML file * @return void */ function importXML() { $link = 'index.php?option=com_sql2excel&view=sqlexcelimportxml'; $this->setRedirect( $link ); } }