/** * Compacts the ordering sequence of the selected records * * @access public * @param string Additional where query to limit ordering to a particular subset of records */ function reorder($where = '') { $k = $this->_tbl_key; if (!in_array('ordering', array_keys($this->getProperties()))) { $this->setError(get_class($this) . ' does not support ordering'); return false; } if ($this->_tbl == '#__content_frontpage') { $order2 = ", content_id DESC"; } else { $order2 = ""; } $query = 'SELECT ' . $this->_tbl_key . ', ordering' . ' FROM ' . $this->_tbl . ' WHERE ordering >= 0' . ($where ? ' AND ' . $where : '') . ' ORDER BY ordering' . $order2; $this->_db->setQuery($query); if (!($orders = $this->_db->loadObjectList())) { $this->setError($this->_db->getErrorMsg()); return false; } // compact the ordering numbers for ($i = 0, $n = count($orders); $i < $n; $i++) { if ($orders[$i]->ordering >= 0) { if ($orders[$i]->ordering != $i + 1) { $orders[$i]->ordering = $i + 1; $query = 'UPDATE ' . $this->_tbl . ' SET ordering = ' . (int) $orders[$i]->ordering . ' WHERE ' . $k . ' = ' . $this->_db->Quote($orders[$i]->{$k}); $this->_db->setQuery($query); $this->_db->query(); } } } return true; }
private function SaveOldNumber($inn, $number) { $query = "INSERT INTO #__sro_oldcert (inn,number) VALUES ({$inn},{$number})"; $this->_db->setQuery($query); if (!$this->_db->query()) { $this->setError("Ошибка при обновлении:" . $this->_db->getErrorMsg()); } return true; }
/** * Funzione per eseguire un aggiornamento nel database * FUNZIONE CHIAMATA DAL MODULO DEVE ESSERE SEMPRE IMPLEMENTATA QUI * @param string Nome della tabella * @param array Valori da inserire * @param string Condizione WHERE completea * @return boolean Torna l'esito della query (TRUE o FALSE) */ public function queryUpdate($table, $values, $where) { $q = $this->buildQueryUpdate($table, $values, $where); $this->db->setQuery($q); $result = $this->db->query(); if ($result === FALSE) { return false; } else { return true; } }
/** * Method to set the publishing state for a row or list of rows in the database * table. The method respects checked out rows by other users and will attempt * to checkin rows that it can after adjustments are made. * * @param mixed $pks An optional array of primary key values to update. If not set the instance property value is used. * @param integer $state The publishing state. eg. [0 = unpublished, 1 = published] * @param integer $userId The user id of the user performing the operation. * * @return boolean True on success. * * @link http://docs.joomla.org/JTable/publish * @since 11.1 */ public function publish($pks = null, $state = 1, $userId = 0) { // Initialise variables. $k = $this->_tbl_key; // Sanitize input. JArrayHelper::toInteger($pks); $userId = (int) $userId; $state = (int) $state; // If there are no primary keys set check to see if the instance key is set. if (empty($pks)) { if ($this->{$k}) { $pks = array($this->{$k}); } else { $e = new JException(JText::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED')); $this->setError($e); return false; } } // Update the publishing state for rows with the given primary keys. $query = $this->_db->getQuery(true); $query->update($this->_tbl); $query->set('published = ' . (int) $state); // Determine if there is checkin support for the table. if (property_exists($this, 'checked_out') || property_exists($this, 'checked_out_time')) { $query->where('(checked_out = 0 OR checked_out = ' . (int) $userId . ')'); $checkin = true; } else { $checkin = false; } // Build the WHERE clause for the primary keys. $query->where($k . ' = ' . implode(' OR ' . $k . ' = ', $pks)); $this->_db->setQuery($query); // Check for a database error. if (!$this->_db->query()) { $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_PUBLISH_FAILED', get_class($this), $this->_db->getErrorMsg())); $this->setError($e); return false; } // If checkin is supported and all rows were adjusted, check them in. if ($checkin && count($pks) == $this->_db->getAffectedRows()) { // Checkin the rows. foreach ($pks as $pk) { $this->checkin($pk); } } // If the JTable instance value is in the list of primary keys that were set, set the instance. if (in_array($this->{$k}, $pks)) { $this->published = $state; } $this->setError(''); return true; }
/** * Method to delete an object from the database. * * @return void * * @since 12.1 * @throws RuntimeException */ protected function doDelete() { // Get the primary key. $primaryKey = $this->getTableKey('primary', 'primary'); // Build the query to delete the item. $query = $this->db->getQuery(true); $query->delete(); $query->from($this->getTableExpression('primary', false)); $query->where($this->getTableKeyExpression('primary', 'primary', false) . ' = ' . (int) $this->{$primaryKey}); // Delete the item. $this->db->setQuery($query); $this->db->query(); }
/** * Set the status property and save it * * Method sets the status property and then saves it immediately * * @param string $status * @return boolean */ function setStatus($status) { //status_id :special status property for documents //status :standard status property for all other objects if (!isset($this->status_id) && !isset($this->status)) { return false; } if (isset($this->status)) { $property = 'status'; } else { $property = 'status_id'; } $this->{$property} = $status; //building the query $query = "UPDATE `" . $this->_tbl . "`" . " SET `" . $property . "` = '" . $this->{$property} . "'" . " WHERE `id` = '" . $this->id . "'"; return $this->_db->query($query); }
protected function _removeAttachment($data) { $result = array(); // only registered users when the board is online will endup here // $data has already been escaped as part of this class // TODO: Get attachment details $query = "SELECT a.*, m.*\n\t\t\tFROM #__kunena_attachments AS a\n\t\t\tJOIN #__kunena_messages AS m ON a.mesid = m.id\n\t\t\tWHERE a.id = '" . $data . "'"; $this->_db->setQuery($query); $attachment = $this->_db->loadObject(); if ($this->_db->getErrorNum()) { $result = array('status' => '-1', 'error' => KunenaError::getDatabaseError()); return $result; } // Verify permissions, user must be author of the message this // attachment is attached to or be a moderator or admin of the site if ($attachment->userid != $this->_my->id && !CKunenaTools::isModerator($this->_my->id, $attachment->catid) && !CKunenaTools::isAdmin()) { // not the author, not a moderator, not an admin // nothing todo here - end with permission error $result = array('status' => '-1', 'error' => JText::_('COM_KUNENA_AJAX_PERMISSION_DENIED')); return $result; } // Request coming form valid user, moderator or admin... // First remove files from filsystem - check for thumbs and raw in case this is an image if (file_exists(JPATH_ROOT . $attachment->folder . $attachment->filename)) { JFile::delete(JPATH_ROOT . $attachment->folder . $attachment->filename); } if (file_exists(JPATH_ROOT . $attachment->folder . '/raw/' . $attachment->filename)) { JFile::delete(JPATH_ROOT . $attachment->folder . '/raw/' . $attachment->filename); } if (file_exists(JPATH_ROOT . $attachment->folder . '/thumb/' . $attachment->filename)) { JFile::delete(JPATH_ROOT . $attachment->folder . '/thumb/' . $attachment->filename); } // Finally delete attachment record from db $query = "DELETE FROM #__kunena_attachments AS a\n\t\t\t\t\tWHERE a.id = {$this->_db->Quote($data)}"; $this->_db->setQuery($query); $this->_db->query(); if ($this->_db->getErrorNum()) { $result = array('status' => '-1', 'error' => KunenaError::getDatabaseError()); } else { $result = array('status' => '1', 'error' => JText::_('COM_KUNENA_AJAX_ATTACHMENT_DELETED')); } return $result; }
/** * Description * * @access public * @param $oid * @param $log */ function hit() { if (!in_array('hits', array_keys($this->getProperties()))) { return; } $k = $this->_tbl_key; $query = $this->_db->getQuery(true); $query->update($this->_db->quoteName($this->_tbl)); $query->set(' hits = ( hits + 1 ) '); // check whether all fields are filled and build where statement for ($i = 0; $i < count($k); $i++) { if ($this->{$k}[$i] === null) { return false; } else { $query->where(' ' . $this->_db->quoteName($k[$i]) . ' = ' . $this->_db->Quote($this->{$k}[$i]) . ' '); } } $this->_db->setQuery($query); $this->_db->query(); $this->hits++; }
/** * Generic Publish/Unpublish function * * @access public * @param array An array of id numbers * @param integer 0 if unpublishing, 1 if publishing * @param integer The id of the user performnig the operation * @since 1.0.4 */ function publish($cid = null, $publish = 1, $user_id = 0) { JArrayHelper::toInteger($cid); $user_id = (int) $user_id; $publish = (int) $publish; $k = $this->_tbl_key; if (count($cid) < 1) { if ($this->{$k}) { $cid = array($this->{$k}); } else { $this->setError("No items selected."); return false; } } $cids = $k . '=' . implode(' OR ' . $k . '=', $cid); $query = 'UPDATE ' . $this->_tbl . ' SET published = ' . (int) $publish . ' WHERE (' . $cids . ')'; $checkin = in_array('checked_out', array_keys($this->getProperties())); if ($checkin) { $query .= ' AND (checked_out = 0 OR checked_out = ' . (int) $user_id . ')'; } $this->_db->setQuery($query); if (!$this->_db->query()) { $this->setError($this->_db->getErrorMsg()); return false; } if (count($cid) == 1 && $checkin) { if ($this->_db->getAffectedRows() == 1) { $this->checkin($cid[0]); if ($this->{$k} == $cid[0]) { $this->published = $publish; } } } $this->setError(''); return true; }
public function unpublishItem(){ $this->db->setQuery("Update #__facileforms_integrator_items Set published = 0 Where id = ".JRequest::getInt('publish_id',-1).""); $this->db->query(); }
public function toggle($id, $property) { $this->db->setQuery('SELECT `' . $property . '` FROM #__acctexp_' . $this->table . ' WHERE `id` = ' . $id); $newstate = $this->db->loadResult() ? 0 : 1; if ($property == 'default') { if (!$newstate) { echo !$newstate; return; } // Reset all other items $this->db->setQuery('UPDATE #__acctexp_' . $this->table . ' SET `' . $property . '` = ' . ($newstate ? 0 : 1) . ' WHERE `id` != ' . $id); $this->db->query(); } $this->db->setQuery('UPDATE #__acctexp_' . $this->table . ' SET `' . $property . '` = ' . $newstate . ' WHERE `id` = ' . $id); $this->db->query(); echo $newstate; }
/** * Execute the query * * @param string the query (optional, it will use the setQuery one otherwise) * @return mixed A database resource if successful, FALSE if not. */ function query($sql = null) { if ($sql !== null) { $this->setQuery($sql); } return $this->_db->query(); }
public function save($form, $formName, $formTitle, array $formOptions, $templateCode, array $areas, $pages = 1) { $templateCodeProcessed = $templateCode; $this->db->setQuery("Select id From #__facileforms_forms Where id = " . $this->db->Quote($form) . ""); if (count($this->db->loadObjectList()) == 0) { $this->db->setQuery("Insert Into #__facileforms_forms \n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tpackage,\n\t\t\t\t\t\t\ttemplate_code,\n\t\t\t\t\t\t\ttemplate_areas,\n\t\t\t\t\t\t\tpublished,\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\tclass1,\n\t\t\t\t\t\t\twidth,\n\t\t\t\t\t\t\theight,\n\t\t\t\t\t\t\tpages\n\t\t\t\t\t\t) \n\t\t\t\t\t\tValues \n\t\t\t\t\t\t(\n\t\t\t\t\t\t\t'EasyModeForms',\n\t\t\t\t\t\t\t" . trim($this->db->Quote($templateCode), "\t, ,\n,\r") . ",\n\t\t\t\t\t\t\t" . $this->db->Quote(Zend_Json::encode($areas)) . ",\n\t\t\t\t\t\t\t'1',\n\t\t\t\t\t\t\t" . trim($this->db->Quote($formName), "\t, ,\n,\r") . ",\n\t\t\t\t\t\t\t" . trim($this->db->Quote($formTitle), "\t, ,\n,\r") . ",\n\t\t\t\t\t\t\t'',\n\t\t\t\t\t\t\t'400',\n\t\t\t\t\t\t\t'500',\n\t\t\t\t\t\t\t" . $this->db->Quote($pages) . "\n\t\t\t\t\t\t)"); $this->db->query(); $form = $this->db->insertid(); } else { $this->db->setQuery("Update \n\t\t\t\t\t\t\t#__facileforms_forms\n\t\t\t\t\t\t Set \n\t\t\t\t\t\t\ttemplate_code = " . $this->db->Quote(trim($templateCode), "\t, ,\n,\r") . ",\n\t\t\t\t\t\t\ttemplate_areas = " . $this->db->Quote(Zend_Json::encode($areas)) . ",\n\t\t\t\t\t\t\tname = " . trim($this->db->Quote($formName), "\t, ,\n,\r") . ",\n\t\t\t\t\t\t\ttitle = " . trim($this->db->Quote($formTitle), "\t, ,\n,\r") . ",\n\t\t\t\t\t\t\tpages = " . $this->db->Quote($pages) . "\n\t\t\t\t\t\t Where\n\t\t\t\t\t\t\tid = " . $this->db->Quote($form) . "\n\t\t\t\t\t\t"); $this->db->query(); } $notRemoveIds = ''; $i = 0; foreach ($areas as $area) { $elementCount = 0; foreach ($area['elements'] as $element) { $elementId = -1; if ($element['dbId'] == 0) { $this->db->setQuery("Insert Into #__facileforms_elements\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\tmailback,\n\t\t\t\t\t\t\t\tmailbackfile,\n\t\t\t\t\t\t\t\tform,\n\t\t\t\t\t\t\t\tpage,\n\t\t\t\t\t\t\t\tpublished,\n\t\t\t\t\t\t\t\tordering,\n\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\ttype,\n\t\t\t\t\t\t\t\tclass1,\n\t\t\t\t\t\t\t\tclass2,\n\t\t\t\t\t\t\t\tlogging,\n\t\t\t\t\t\t\t\tposx,\n\t\t\t\t\t\t\t\tposxmode,\n\t\t\t\t\t\t\t\tposy,\n\t\t\t\t\t\t\t\tposymode,\n\t\t\t\t\t\t\t\twidth,\n\t\t\t\t\t\t\t\twidthmode,\n\t\t\t\t\t\t\t\theight,\n\t\t\t\t\t\t\t\theightmode,\n\t\t\t\t\t\t\t\tflag1,\n\t\t\t\t\t\t\t\tflag2,\n\t\t\t\t\t\t\t\tdata1,\n\t\t\t\t\t\t\t\tdata2,\n\t\t\t\t\t\t\t\tdata3,\n\t\t\t\t\t\t\t\tscript1cond,\n\t\t\t\t\t\t\t\tscript1id,\n\t\t\t\t\t\t\t\tscript1code,\n\t\t\t\t\t\t\t\tscript1flag1,\n\t\t\t\t\t\t\t\tscript1flag2,\n\t\t\t\t\t\t\t\tscript2cond,\n\t\t\t\t\t\t\t\tscript2id,\n\t\t\t\t\t\t\t\tscript2code,\n\t\t\t\t\t\t\t\tscript2flag1,\n\t\t\t\t\t\t\t\tscript2flag2,\n\t\t\t\t\t\t\t\tscript2flag3,\n\t\t\t\t\t\t\t\tscript2flag4,\n\t\t\t\t\t\t\t\tscript2flag5,\n\t\t\t\t\t\t\t\tscript3cond,\n\t\t\t\t\t\t\t\tscript3id,\n\t\t\t\t\t\t\t\tscript3code,\n\t\t\t\t\t\t\t\tscript3msg\n\t\t\t\t\t\t\t) \n\t\t\t\t\t\t\tValues \n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['mailback']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['mailbackfile']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($form) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote(isset($element['page']) ? $element['page'] : 1) . ",\n\t\t\t\t\t\t\t\t'1',\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['orderNumber'] > -1 ? $element['orderNumber'] : $element['appElementOrderId']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['name']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['title']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['bfType']) . ",\n\t\t\t\t\t\t\t\t'',\n\t\t\t\t\t\t\t\t'',\n\t\t\t\t\t\t\t\t'1',\n\t\t\t\t\t\t\t\t'0',\n\t\t\t\t\t\t\t\t'0',\n\t\t\t\t\t\t\t\t'" . 40 * $elementCount . "',\n\t\t\t\t\t\t\t\t'0',\n\t\t\t\t\t\t\t\t'20',\n\t\t\t\t\t\t\t\t'0',\n\t\t\t\t\t\t\t\t'20',\n\t\t\t\t\t\t\t\t'0',\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['flag1']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['flag2']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['data1']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['data2']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['data3']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script1cond']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script1id']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script1code']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script1flag1']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script1flag2']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script2cond']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script2id']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script2code']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script2flag1']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script2flag2']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script2flag3']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script2flag4']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script2flag5']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script3cond']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script3id']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script3code']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script3msg']) . "\n\t\t\t\t\t\t\t)"); $this->db->query(); $elementId = $this->db->insertid(); $areas[$i]['elements'][$elementCount]['dbId'] = $elementId; } else { // fix ids of copied elements $this->db->setQuery("Select id From #__facileforms_elements Where name = " . $this->db->Quote($element['name']) . " And form = " . $this->db->Quote($form) . " "); $elementCheck = $this->db->loadObjectList(); foreach ($elementCheck as $check) { if ($check->id != intval($element['dbId'])) { $element['dbId'] = $check->id; $areas[$i]['elements'][$elementCount]['dbId'] = $check->id; } break; } $this->db->setQuery("Update #__facileforms_elements Set\n\t\t\t\t\t\t\t\tmailback=" . $this->db->Quote($element['mailback']) . ",\n\t\t\t\t\t\t\t\tmailbackfile=" . $this->db->Quote($element['mailbackfile']) . ",\n\t\t\t\t\t\t\t\tform=" . $this->db->Quote($form) . ",\n\t\t\t\t\t\t\t\tpage=" . $this->db->Quote(isset($element['page']) ? $element['page'] : 1) . ",\n\t\t\t\t\t\t\t\tpublished='1',\n\t\t\t\t\t\t\t\tordering=" . $this->db->Quote($element['orderNumber'] > -1 ? $element['orderNumber'] : $element['appElementOrderId']) . ",\n\t\t\t\t\t\t\t\tname=" . $this->db->Quote($element['name']) . ",\n\t\t\t\t\t\t\t\ttitle=" . $this->db->Quote($element['title']) . ",\n\t\t\t\t\t\t\t\ttype=" . $this->db->Quote($element['bfType']) . ",\n\t\t\t\t\t\t\t\tclass1='',\n\t\t\t\t\t\t\t\tclass2='',\n\t\t\t\t\t\t\t\tlogging='1',\n\t\t\t\t\t\t\t\tposx='0',\n\t\t\t\t\t\t\t\tposxmode='0',\n\t\t\t\t\t\t\t\tposy='" . 40 * $elementCount . "',\n\t\t\t\t\t\t\t\tposymode='0',\n\t\t\t\t\t\t\t\twidth='20',\n\t\t\t\t\t\t\t\twidthmode='0',\n\t\t\t\t\t\t\t\theight='20',\n\t\t\t\t\t\t\t\theightmode='0',\n\t\t\t\t\t\t\t\tflag1=" . $this->db->Quote($element['flag1']) . ",\n\t\t\t\t\t\t\t\tflag2=" . $this->db->Quote($element['flag2']) . ",\n\t\t\t\t\t\t\t\tdata1=" . $this->db->Quote($element['data1']) . ",\n\t\t\t\t\t\t\t\tdata2=" . $this->db->Quote($element['data2']) . ",\n\t\t\t\t\t\t\t\tdata3=" . $this->db->Quote($element['data3']) . ",\n\t\t\t\t\t\t\t\tscript1cond=" . $this->db->Quote($element['script1cond']) . ",\n\t\t\t\t\t\t\t\tscript1id=" . $this->db->Quote($element['script1id']) . ",\n\t\t\t\t\t\t\t\tscript1code=" . $this->db->Quote($element['script1code']) . ",\n\t\t\t\t\t\t\t\tscript1flag1=" . $this->db->Quote($element['script1flag1']) . ",\n\t\t\t\t\t\t\t\tscript1flag2=" . $this->db->Quote($element['script1flag2']) . ",\n\t\t\t\t\t\t\t\tscript2cond=" . $this->db->Quote($element['script2cond']) . ",\n\t\t\t\t\t\t\t\tscript2id=" . $this->db->Quote($element['script2id']) . ",\n\t\t\t\t\t\t\t\tscript2code=" . $this->db->Quote($element['script2code']) . ",\n\t\t\t\t\t\t\t\tscript2flag1=" . $this->db->Quote($element['script2flag1']) . ",\n\t\t\t\t\t\t\t\tscript2flag2=" . $this->db->Quote($element['script2flag2']) . ",\n\t\t\t\t\t\t\t\tscript2flag3=" . $this->db->Quote($element['script2flag3']) . ",\n\t\t\t\t\t\t\t\tscript2flag4=" . $this->db->Quote($element['script2flag4']) . ",\n\t\t\t\t\t\t\t\tscript2flag5=" . $this->db->Quote($element['script2flag5']) . ",\n\t\t\t\t\t\t\t\tscript3cond=" . $this->db->Quote($element['script3cond']) . ",\n\t\t\t\t\t\t\t\tscript3id=" . $this->db->Quote($element['script3id']) . ",\n\t\t\t\t\t\t\t\tscript3code=" . $this->db->Quote($element['script3code']) . ",\n\t\t\t\t\t\t\t\tscript3msg=" . $this->db->Quote($element['script3msg']) . "\n\t\t\t\t\t\t\tWhere\n\t\t\t\t\t\t\t\tid = " . $this->db->Quote($element['dbId']) . "\n\t\t\t\t\t\t\t"); $this->db->query(); $elementId = $element['dbId']; } $notRemoveIds .= ' id<>' . $this->db->Quote($elementId) . ' And '; $templateCodeProcessed = str_replace('ff_listItem' . $element['rndId'], 'ff_listItem' . $elementId, $templateCodeProcessed); $templateCodeProcessed = str_replace('ff_iconCaption' . $element['rndId'], 'ff_iconCaption' . $elementId, $templateCodeProcessed); $templateCodeProcessed = str_replace('ff_dragBox' . $element['rndId'], 'ff_dragBox' . $elementId, $templateCodeProcessed); $templateCodeProcessed = str_replace('ff_label' . $element['rndId'], 'ff_label' . $elementId, $templateCodeProcessed); $templateCodeProcessed = str_replace('ff_elem' . $element['rndId'], 'ff_elem' . $elementId, $templateCodeProcessed); $templateCodeProcessed = str_replace('ff_nm_' . $element['rndId'] . '[]', 'ff_nm_' . $element['name'] . '[]', $templateCodeProcessed); $templateCodeProcessed = str_replace('ff_static' . $element['rndId'], 'ff_static' . $elementId, $templateCodeProcessed); $templateCodeProcessed = str_replace('ff_div' . $element['rndId'], 'ff_div' . $elementId, $templateCodeProcessed); $templateCodeProcessed = str_replace('ff_captcha' . $element['rndId'], 'ff_captcha' . $elementId, $templateCodeProcessed); $templateCodeProcessed = str_replace('ff_capimg' . $element['rndId'], 'ff_capimg' . $elementId, $templateCodeProcessed); $templateCodeProcessed = str_replace('ff_break' . $element['rndId'], 'ff_break' . $elementId, $templateCodeProcessed); $templateCodeProcessed = str_replace('readonly="readonly"', 'disabled="disabled"', $templateCodeProcessed); $elementCount++; } $i++; } if (strlen($notRemoveIds) != 0) { $this->db->setQuery("Delete From #__facileforms_elements Where " . $notRemoveIds . " form = " . $this->db->Quote($form) . " "); $this->db->query(); } else { $this->db->setQuery("Delete From #__facileforms_elements Where form = " . $this->db->Quote($form) . " "); $this->db->query(); } $this->db->setQuery("Update \n\t\t\t\t\t\t\t#__facileforms_forms\n\t\t\t\t\t\t Set \n\t\t\t\t\t\t\ttemplate_code_processed = " . $this->db->Quote(trim($templateCodeProcessed)) . ",\n\t\t\t\t\t\t\ttemplate_areas = " . $this->db->Quote(Zend_Json::encode($areas)) . "\n\t\t\t\t\t\t Where\n\t\t\t\t\t\t\tid = " . $this->db->Quote($form) . "\n\t\t\t\t\t\t"); $this->db->query(); return $form; }
function expcsv(array $ids) { global $ff_config; $csvdelimiter = stripslashes($ff_config->csvdelimiter); $csvquote = stripslashes($ff_config->csvquote); $cellnewline = $ff_config->cellnewline == 0 ? "\n" : "\\n"; $fields = array(); $lines = array(); $ids = implode(',', $ids); $this->db->setQuery( "select * from #__facileforms_records where id in ($ids) order by submitted Desc" ); $recs = $this->db->loadObjectList(); $recsSize = count($recs); for($r = 0; $r < $recsSize; $r++) { $rec = $recs[$r]; $lineNum = count($lines); $fields['ZZZ_A_ID'] = true; $fields['ZZZ_B_SUBMITTED'] = true; $fields['ZZZ_C_USER_ID'] = true; $fields['ZZZ_D_USERNAME'] = true; $fields['ZZZ_E_USER_FULL_NAME'] = true; $fields['ZZZ_F_TITLE'] = true; $fields['ZZZ_G_IP'] = true; $fields['ZZZ_H_BROWSER'] = true; $fields['ZZZ_I_OPSYS'] = true; $fields['ZZZ_J_TRANSACTION_ID'] = true; $fields['ZZZ_K_DATE'] = true; $fields['ZZZ_L_TEST_ACCOUNT'] = true; $fields['ZZZ_M_DOWNLOAD_TRIES'] = true; $lines[$lineNum]['ZZZ_A_ID'][] = $rec->id; $lines[$lineNum]['ZZZ_B_SUBMITTED'][] = $rec->submitted; $lines[$lineNum]['ZZZ_C_USER_ID'][] = $rec->user_id; $lines[$lineNum]['ZZZ_D_USERNAME'][] = $rec->username; $lines[$lineNum]['ZZZ_E_USER_FULL_NAME'][] = $rec->user_full_name; $lines[$lineNum]['ZZZ_F_TITLE'][] = $rec->title; $lines[$lineNum]['ZZZ_G_IP'][] = $rec->ip; $lines[$lineNum]['ZZZ_H_BROWSER'][] = $rec->browser; $lines[$lineNum]['ZZZ_I_OPSYS'][] = $rec->opsys; $lines[$lineNum]['ZZZ_J_TRANSACTION_ID'][] = $rec->paypal_tx_id; $lines[$lineNum]['ZZZ_K_DATE'][] = $rec->paypal_payment_date; $lines[$lineNum]['ZZZ_L_TEST_ACCOUNT'][] = $rec->paypal_testaccount; $lines[$lineNum]['ZZZ_M_DOWNLOAD_TRIES'][] = $rec->paypal_download_tries; $rec = $recs[$r]; $this->db->setQuery( "select Distinct * from #__facileforms_subrecords where record = $rec->id order by id" ); $subs = $this->db->loadObjectList(); $subsSize = count($subs); for($s = 0; $s < $subsSize; $s++) { $sub = $subs[$s]; if($sub->name != 'bfFakeName' && $sub->name != 'bfFakeName2' && $sub->name != 'bfFakeName3' && $sub->name != 'bfFakeName4'){ if(!isset($fields[strtoupper($sub->name)])) { $fields[strtoupper($sub->name)] = true; } $lines[$lineNum][strtoupper($sub->name)][] = $sub->value; } } } $head = ''; ksort($fields); $lineLength = count($lines); foreach($fields As $fieldName => $null) { $head .= $csvquote.$fieldName.$csvquote.$csvdelimiter; for($i = 0; $i < $lineLength;$i++) { if(!isset($lines[$i][$fieldName])) { $lines[$i][$fieldName] = array(); } } } $head = substr($head,0,strlen($head)-1) . nl(); $out = ''; for($i = 0; $i < $lineLength;$i++) { ksort($lines[$i]); foreach($lines[$i] As $line){ $out .= $csvquote.str_replace($csvquote,$csvquote.$csvquote,str_replace("\n",$cellnewline,str_replace("\r","",implode('|',$line)))).$csvquote.$csvdelimiter; } $out = substr($out,0,strlen($out)-1); $out .= nl(); } $csvname = JPATH_SITE.'/components/com_breezingforms/exports/ffexport-'.date('YmdHis').'.csv'; JFile::makeSafe($csvname); if (!JFile::write($csvname,$head.$out)) { echo "<script> alert('".addslashes(BFText::_('COM_BREEZINGFORMS_RECORDS_XMLNORWRTBL'))."'); window.history.go(-1);</script>\n"; exit(); } // if $this->db->setQuery( "update #__facileforms_records set exported=1 where id in ($ids)" ); $this->db->query(); /* $data = JFile::read($csvname); $files[] = array('name' => basename($csvname), 'data' => $data); $zip = JArchive::getAdapter('zip'); $path = JPATH_SITE.'/components/com_breezingforms/exports/ffexport-csv-'.date('YmdHis').'.zip'; $zip->create($path, $files); JFile::delete($csvname); */ @ob_end_clean(); $_size = filesize($csvname); $_name = basename($csvname); @ini_set("zlib.output_compression", "Off"); Header("Content-Type: text/comma-separated-values; charset=utf-8"); Header("Content-Disposition: attachment;filename=\"$_name\""); Header("Content-Transfer-Encoding: 8bit"); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: private"); //header("Content-Type: application/octet-stream"); //header("Content-Disposition: attachment; filename=$_name"); //header("Accept-Ranges: bytes"); //header("Content-Length: $_size"); ob_start(); readfile($csvname); $c = ob_get_contents(); ob_end_clean(); if(function_exists('mb_convert_encoding')){ echo chr(255).chr(254).mb_convert_encoding( $c, 'UTF-16LE', 'UTF-8'); } else { echo $c; } exit; }