/** * Function to export donor list to CSV. * * @return void * * @since 1.0.0 */ public function export_donors() { $app = JFactory::getApplication(); $params = JComponentHelper::getParams('com_cmdonation'); $campaignId = $app->input->get('campaign', 0, 'integer'); // Make sure campaign exists. $campaign = JModelAdmin::getInstance('Campaign', 'CMDonationModel')->getItem($campaignId); if (empty($campaign)) { $app->enqueueMessage(JText::_('COM_CMDONATION_CAMPAIGN_NOT_FOUND'), 'error'); $app->redirect(JRoute::_('index.php?option=com_cmdonation')); } // Get campaign's donations. $donations = JModelAdmin::getInstance('Donations', 'CMDonationModel')->getDonationsForCSV($campaignId); $data = array(array(JText::_('COM_CMDONATION_DONATION_FIRST_NAME_LABEL'), JText::_('COM_CMDONATION_DONATION_LAST_NAME_LABEL'), JText::_('COM_CMDONATION_DONATION_EMAIL_LABEL'), JText::_('COM_CMDONATION_DONATION_COUNTRY_LABEL'), JText::_('COM_CMDONATION_DONATION_AMOUNT_LABEL'), JText::_('COM_CMDONATION_DONATION_COMPLETED_LABEL'), JText::_('COM_CMDONATION_DONATION_PAYMENT_METHOD_LABEL'))); if (!empty($donations)) { include JPATH_ROOT . '/administrator/components/com_cmdonation/helpers/countries.php'; $currencySign = $params->get('currency_sign'); $currencySignPosition = $params->get('currency_sign_position'); $decimals = $params->get('decimals'); $decimalPoint = $params->get('decimal_point'); $thousandSeparator = $params->get('thousand_separator'); foreach ($donations as $donation) { if (array_key_exists($donation->country_code, $countryList)) { $countryName = JText::_($countryList[$donation->country_code]); } else { $countryName = ''; } $amount = CMDonationHelper::showDonationAmount($donation->amount, $currencySign, $currencySignPosition, $decimals, $decimalPoint, $thousandSeparator, false); $paymentMethod = CMDonationHelper::displayPaymentMethodName($donation->payment_method_id); $data[] = array($donation->first_name, $donation->last_name, $donation->email, $countryName, $amount, $donation->completed, $paymentMethod); } } $delimiter = $params->get('csv_delimiter_character', ','); $enclosure = $params->get('csv_enclosure_character', 'double'); if ($enclosure == 'double') { $enclosure = '"'; } else { $enclosure = "'"; } $filename = JApplication::stringURLSafe($campaign->name); if ($filename == '') { $filename = JFactory::getDate()->format("Y-m-d-H-i-s"); } $filename .= '.csv'; header("Content-type: text/csv"); header("Content-Disposition: attachment; filename={$filename}"); header("Pragma: no-cache"); header("Expires: 0"); $output = fopen("php://output", "w"); foreach ($data as $row) { fputcsv($output, $row, $delimiter, $enclosure); } fclose($output); JFactory::getApplication()->close(); }
function onAfterSaveUser($user, $isnew, $success, $msg) { $mainframe = JFactory::getApplication(); $task = JRequest::getCmd('task'); if ($mainframe->isSite() && $task != 'activate') { JLoader::register('TZ_PortfolioModelUser', JPATH_ADMINISTRATOR . '/components/com_tz_portfolio/models/user.php'); $model = JModelAdmin::getInstance('User', 'TZ_PortfolioModel', array('ignore_request' => true)); $avatar = JRequest::getVar('jform', '', 'files', 'array'); $description = JRequest::getVar('description', '', 'post', 'string', JREQUEST_ALLOWHTML); $deleteImage = JRequest::getCmd('delete_images'); $currentImage = JRequest::getString('current_images'); $userData['url'] = JRequest::getVar('url', '', 'post', 'string'); $description = trim($description); $userData['usersid'] = $user['id']; $userData['gender'] = JRequest::getCmd('gender'); $userData['description'] = $description; $userData['twitter'] = JRequest::getVar('url_twitter', '', 'post', 'string'); $userData['facebook'] = JRequest::getVar('url_facebook', '', 'post', 'string'); $userData['google_one'] = JRequest::getVar('url_google_one_plus', '', 'post', 'string'); $image = null; if (!$userData['gender']) { $userData['gender'] = 'm'; } if (!empty($avatar['name']['client_images'])) { $image = $avatar; } else { if (!empty($data['url_images'])) { $image = $data['url_images']; } } if ($image) { $model->deleteImages($currentImage); if (!($userData['images'] = $model->uploadImages($image))) { $this->setError($this->getError()); return false; } } else { $userData['images'] = $currentImage; } if ($deleteImage == 1) { $model->deleteImages($currentImage); $userData['images'] = ''; } if (!empty($userData['url']) || !empty($userData['description']) || !empty($userData['twitter']) || !empty($userData['facebook']) || !empty($userData['google_one']) || !empty($userData['images'])) { if (!$model->saveUser($userData)) { $this->setError($this->getError()); return false; } } } }
public function onItemAfterSave($context, $table, $isNew) { $params = JComponentHelper::getParams('com_djcatalog2'); $app = JFactory::getApplication(); $data = $app->input->get('jform', array(), 'array'); // saving additional categories $db = JFactory::getDbo(); $db->setQuery('DELETE FROM #__djc2_items_categories WHERE item_id=\'' . $table->id . '\''); $category_limit = (int) $params->get('fed_multiple_categories_limit', 3); if ($db->query()) { if (!isset($data['categories'])) { $data['categories'] = array(); } if ($category_limit > 0) { $data['categories'] = array_slice($data['categories'], 0, $category_limit); } $data['categories'][] = $table->cat_id; if (!empty($data['categories'])) { $data['categories'] = array_unique($data['categories']); foreach ($data['categories'] as $cat_id) { if ($cat_id > 0) { $db->setQuery('INSERT INTO #__djc2_items_categories VALUES (\'' . $table->id . '\', \'' . $cat_id . '\')'); $db->query(); } } } } // saving images if (!DJCatalog2ImageHelper::saveImages('item', $table, $params, $isNew)) { $app->enqueueMessage(JText::_('COM_DJCATALOG2_ERROR_SAVING_IMAGES'), 'error'); } // saving attachments if (!DJCatalog2FileHelper::saveFiles('item', $table, $params, $isNew)) { $app->enqueueMessage(JText::_('COM_DJCATALOG2_ERROR_SAVING_FILES'), 'error'); } // saving additional attributes $attribs = $app->input->get('attribute', array(), 'array'); $model = JModelAdmin::getInstance('Itemform', 'Djcatalog2Model', array()); if (!$model->saveAttributes($attribs, $table)) { $app->enqueueMessage($model->getError(), 'error'); } }
/** * Method to delete an download. * * * @return Boolean True if successful, false otherwise. */ public function delete() { // Load the backend download model require_once JPATH_ADMINISTRATOR . '/components/com_jdownloads/models/download.php'; $jinput = JFactory::getApplication()->input; $id = $jinput->get('a_id', 0, 'int'); // load the download data $model_download = JModelAdmin::getInstance('Download', 'jdownloadsModel'); $data = $this->getModel()->getItem($id); $this->option = 'com_jdownloads'; // check permissions if ($data->params->get('access-delete') == true) { if ($id > 0) { $result = $model_download->delete($id); } } else { // no permissions - do nothing JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR')); return false; } // Add a message to the message queue $application = JFactory::getApplication(); if ($result) { $application->enqueueMessage(JText::_('COM_JDOWNLOADS_DOWNLOAD_DELETED_MSG'), 'message'); } else { $application->enqueueMessage(JText::_('COM_JDOWNLOADS_DOWNLOAD_DELETED_MSG_ERROR'), 'error'); } // Redirect to the download view page. $this->setRedirect(JRoute::_('index.php?option=com_jdownloads&view=downloads')); return $result; }
function onAfterDispatch() { JFactory::getLanguage()->load('com_tz_portfolio'); $mainframe = JFactory::getApplication(); if ($mainframe->isAdmin()) { return; } if ($this->params->get('override_user_form', 1)) { $option = JRequest::getCmd('option'); $view = JRequest::getCmd('view'); $task = JRequest::getCmd('task'); $layout = JRequest::getCmd('layout'); $user = JFactory::getUser(); if ($option == 'com_users' && $view == 'registration' && !$layout) { JLoader::register('UsersController', JPATH_ADMINISTRATOR . '/components/com_users/controller.php'); $controller = JControllerLegacy::getInstance('Controller', array('name' => 'Users')); $views = $controller->getView($view, 'html'); $tplName = JFactory::getApplication()->getTemplate(); $tplPath = JPATH_THEMES . DIRECTORY_SEPARATOR . $tplName . DIRECTORY_SEPARATOR . 'html' . DIRECTORY_SEPARATOR . 'com_tz_portfolio' . DIRECTORY_SEPARATOR . 'users'; if (!JFile::exists($tplPath . DIRECTORY_SEPARATOR . 'register.php')) { $tplPath = JPATH_SITE . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_tz_portfolio' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'users' . DIRECTORY_SEPARATOR . 'tmpl'; } $views->addTemplatePath($tplPath); $views->setLayout('register'); ob_start(); $views->display(); $contents = ob_get_clean(); $document = JFactory::getDocument(); $document->setBuffer($contents, 'component'); } if ($user->username && $option == 'com_users' && $view == 'profile' && ($layout == 'edit' || $task == 'profile.edit')) { JLoader::register('UsersController', JPATH_ADMINISTRATOR . '/components/com_users/controller.php'); $controller = JControllerLegacy::getInstance('Controller', array('name' => 'Users')); $views = $controller->getView($view, 'html'); $tplName = JFactory::getApplication()->getTemplate(); $tplPath = JPATH_THEMES . DIRECTORY_SEPARATOR . $tplName . DIRECTORY_SEPARATOR . 'html' . DIRECTORY_SEPARATOR . 'com_tz_portfolio' . DIRECTORY_SEPARATOR . 'users'; if (!JFile::exists($tplPath . DIRECTORY_SEPARATOR . 'profile.php')) { $tplPath = JPATH_SITE . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_tz_portfolio' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'users' . DIRECTORY_SEPARATOR . 'tmpl'; } $views->addTemplatePath($tplPath); $views->setLayout('profile'); JLoader::register('TZ_PortfolioModelUser', JPATH_ADMINISTRATOR . '/components/com_tz_portfolio/models/user.php'); $model = JModelAdmin::getInstance('User', 'TZ_PortfolioModel', array('ignore_request' => true)); $userData = $model->getUsers($user->id); $views->assign('TZUser', $userData); ob_start(); $active = JFactory::getApplication()->getMenu()->getActive(); if (isset($active->query['layout']) && $active->query['layout'] != 'profile') { $active->query['layout'] = 'profile'; } $views->assign('user', $user); $views->display(); $contents = ob_get_clean(); $document = JFactory::getDocument(); $document->setBuffer($contents, 'component'); } } }
public function onFieldAfterDelete($context, $table) { $params = JComponentHelper::getParams('com_djcatalog2'); $app = JFactory::getApplication(); $model = JModelAdmin::getInstance('Field', 'Djcatalog2Model', array()); if (!$model->deleteOptions($table)) { $app->enqueueMessage($model->getError(), 'error'); } }
public function uninstall($eid = array()) { $user = JFactory::getUser(); $app = JFactory::getApplication(); $view = $app->input->getCmd('view'); if ($user->authorise('core.delete', 'com_tz_portfolio_plus')) { $failed = array(); /* * Ensure eid is an array of extension ids in the form id => client_id * TODO: If it isn't an array do we want to set an error and fail? */ if (!is_array($eid)) { $eid = array($eid => 0); } // Get an installer object for the extension type $row = $this->getTable(); $template_table = $this->getTable('Templates'); $template_default = $template_table->getHome(); $template_style = JModelAdmin::getInstance('Template_Style', 'TZ_Portfolio_PlusModel', array('ignore_request' => true)); // Uninstall the chosen extensions $msgs = array(); $result = false; foreach ($eid as $id) { $id = trim($id); $row->load($id); $langstring = 'COM_TZ_PORTFOLIO_PLUS_' . strtoupper($row->type); $rowtype = JText::_($langstring); if (strpos($rowtype, $langstring) !== false) { $rowtype = $row->type; } if ($row->type && $row->type == 'tz_portfolio_plus-template') { // Is the template we are trying to uninstall a core one? // Because that is not a good idea... if ($row->protected) { JLog::add(JText::sprintf('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_WARNCORETEMPLATE', JText::_('COM_TZ_PORTFOLIO_PLUS_' . $view)), JLog::WARNING, 'jerror'); return false; } if ($template_default->template == $row->element) { $msg = JText::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_TEMPLATE_DEFAULT'); $app->enqueueMessage($msg, 'warning'); return false; } $tpl_path = COM_TZ_PORTFOLIO_PLUS_PATH_SITE . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $row->element; if (JFolder::exists($tpl_path)) { if (!$template_style->deleteTemplate($row->name)) { $app->enqueueMessage($template_style->getError(), 'warning'); return false; } if (JFolder::delete($tpl_path)) { $result = $this->delete($id); } } // Build an array of extensions that failed to uninstall if ($result === false) { // There was an error in uninstalling the package $msgs[] = JText::sprintf('COM_TZ_PORTFOLIO_PLUS_UNINSTALL_ERROR', JText::_('COM_TZ_PORTFOLIO_PLUS_' . $view)); $result = false; } else { // Package uninstalled sucessfully $msgs[] = JText::sprintf('COM_TZ_PORTFOLIO_PLUS_UNINSTALL_SUCCESS', JText::_('COM_TZ_PORTFOLIO_PLUS_' . $view)); $result = true; } } } $msg = implode("<br />", $msgs); $app->enqueueMessage($msg); return $result; } else { JError::raiseWarning(403, JText::_('JERROR_CORE_DELETE_NOT_PERMITTED')); } }
/** * Method to get create the component and any objects/tables entered. * * @param string $token A form session token used to validate we are on the same form * * @return array An array of the progress (at completion) for the component generation. */ public function wizardsave($data) { $component_model = JModelAdmin::getInstance('Component', 'ComponentArchitectModel', array('ignore_request' => false)); $form = $component_model->getForm(); $component = array(); $fieldsets = $form->getFieldsets(); foreach ($fieldsets as $fieldset) { // Check if a group if (count($form->getGroup($fieldset->name)) <= 0) { $fields = $form->getFieldset($fieldset->name); foreach ($fields as $field) { $component[$field->fieldname] = $form->getFieldAttribute($field->fieldname, 'default', ''); } } else { $fields = $form->getGroup($fieldset->name); if (count($fields) > 0) { foreach ($fields as $field) { $component[$fieldset->name][$field->fieldname] = $form->getFieldAttribute($field->fieldname, 'default', '0', $fieldset->name); } } } } $component['id'] = 0; $component['name'] = $data['component_name']; // Set code name to blank so it is auto generated $component['code_name'] = ''; $component_model->save($component); $default_component_object = 0; for ($i = 0; $i < count($data['component_objects']['name']); $i++) { if ($data['component_objects']['name'][$i] != '') { $component_object_model = JModelAdmin::getInstance('ComponentObject', 'ComponentArchitectModel', array('ignore_request' => false)); $form = $component_object_model->getForm(); $component_object = array(); $fieldsets = $form->getFieldsets(); foreach ($fieldsets as $fieldset) { // Check if a group if (count($form->getGroup($fieldset->name)) <= 0) { $fields = $form->getFieldset($fieldset->name); foreach ($fields as $field) { $component_object[$field->fieldname] = $form->getFieldAttribute($field->fieldname, 'default', ''); } } else { $fields = $form->getGroup($fieldset->name); if (count($fields) > 0) { foreach ($fields as $field) { $component_object[$fieldset->name][$field->fieldname] = $form->getFieldAttribute($field->fieldname, 'default', '', $fieldset->name); } } } } $component_object['id'] = 0; $component_object['component_id'] = $component_model->getState('component.id'); $component_object['name'] = $data['component_objects']['name'][$i]; $component_object['source_table'] = $data['component_objects']['source_table'][$i]; // Set component object plural, code and short names to blank so they are auto generated $component_object['plural_name'] = ''; $component_object['short_name'] = ''; $component_object['short_plural_name'] = ''; // Set component code names to blank so they are auto generated $component_object['code_name'] = ''; $component_object['plural_code_name'] = ''; $component_object_model->save($component_object); // Save id for default component object as first object created if ($default_component_object == 0) { $default_component_object = $component_object_model->getState('componentobject.id'); } unset($component_object_model); } } $pk = $component_model->getState('component.id'); $component_temp = $component_model->getItem($pk); $component['id'] = $pk; $component['default_object_id'] = $default_component_object; $component['code_name'] = $component_temp->code_name; $component['created'] = $component_temp->created; $component['created_by'] = $component_temp->created_by; $component_model->save($component); unset($component_model); return true; }