english/administrator/components/com_aicontactsafe/models/messages.php
// genetare the csv sting with messages
genetare the csv sting with messages
genetare the csv sting with messages
function generateCSV() {
		$csv_text = '';
		$field_separator = ',';
		$line_separator = "<br/>";
		$db = &JFactory::getDBO();
		$cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
		JArrayHelper::toInteger($cid);
		if (count($cid) > 0) {
			$cids = implode(',', $cid);
		} else {
			$cids = '-1';
		}
		if ($cids == '-1') {
			$where = $this->getWhere();
		} else {
			$where = 'WHERE m.id IN ( '.$cids.' )';
		}
		$query = 'SELECT m.*, p.name as profile, s.name as status FROM #__aicontactsafe_messages m LEFT JOIN #__aicontactsafe_profiles p ON m.profile_id = p.id LEFT JOIN #__aicontactsafe_statuses s ON m.status_id = s.id '.$where;
		$db->setQuery($query);
		$messages = $db->loadObjectList();
		foreach($messages as $message) {
			if( $this->checkAccessToMessage($message->id) ) {
				$csv_text .= $message->id .$field_separator;
				$csv_text .= $this->generate_csv_value($message->name) .$field_separator;
				$csv_text .= $this->generate_csv_value($message->email) .$field_separator;
				$csv_text .= $this->generate_csv_value($message->subject) .$field_separator;
				$csv_text .= $message->sender_ip .$field_separator;
				$csv_text .= $this->generate_csv_value($message->profile) .$field_separator;
				$csv_text .= $this->generate_csv_value($message->status) .$field_separator;
				$query = 'SELECT f.id, f.name, f.field_label, f.field_label_message, fv.field_value FROM #__aicontactsafe_fieldvalues fv LEFT JOIN #__aicontactsafe_fields f ON fv.field_id = f.id WHERE fv.message_id = '.$message->id.' ORDER BY f.id';
				$db->setQuery($query);
				$fields = $db->loadObjectList();
				foreach($fields as $field) {
					$csv_text .= $field->id . $field_separator;
					$csv_text .= $field->name . $field_separator;
					$csv_text .= $this->generate_csv_value($field->field_label) . $field_separator;
					$csv_text .= $this->generate_csv_value($field->field_label_message) . $field_separator;
					$csv_text .= $this->generate_csv_value($field->field_value) . $field_separator;
				}
				$csv_text .= $message->date_added .$line_separator;
			}
		}
		$this->_app->_session->set( 'csv_text:' . $this->_sTask, $csv_text );
		return $csv_text;
	}
function generateCSV ( ) { $ csv_text = '' ; $ field_separator = ',' ; $ line_separator = " <br/> " ; $ db = & JFactory :: getDBO ( ) ; $ cid = JRequest :: getVar ( 'cid' , array ( ) , 'post' , 'array' ) ; JArrayHelper :: toInteger ( $ cid ) ; if ( count ( $ cid ) > 0 ) { $ cids = implode ( ',' , $ cid ) ; } else { $ cids = '-1' ; } if ( $ cids == '-1' ) { $ where = $ this -> getWhere ( ) ; } else { $ where = 'WHERE m.id IN ( ' . $ cids . ' )' ; } $ query = 'SELECT m.*, p.name as profile, s.name as status FROM #__aicontactsafe_messages m LEFT JOIN #__aicontactsafe_profiles p ON m.profile_id = p.id LEFT JOIN #__aicontactsafe_statuses s ON m.status_id = s.id ' . $ where ; $ db -> setQuery ( $ query ) ; $ messages = $ db -> loadObjectList ( ) ; foreach ( $ messages as $ message ) { if ( $ this -> checkAccessToMessage ( $ message -> id ) ) { $ csv_text .= $ message -> id . $ field_separator ; $ csv_text .= $ this -> generate_csv_value ( $ message -> name ) . $ field_separator ; $ csv_text .= $ this -> generate_csv_value ( $ message -> email ) . $ field_separator ; $ csv_text .= $ this -> generate_csv_value ( $ message -> subject ) . $ field_separator ; $ csv_text .= $ message -> sender_ip . $ field_separator ; $ csv_text .= $ this -> generate_csv_value ( $ message -> profile ) . $ field_separator ; $ csv_text .= $ this -> generate_csv_value ( $ message -> status ) . $ field_separator ; $ query = 'SELECT f.id, f.name, f.field_label, f.field_label_message, fv.field_value FROM #__aicontactsafe_fieldvalues fv LEFT JOIN #__aicontactsafe_fields f ON fv.field_id = f.id WHERE fv.message_id = ' . $ message -> id . ' ORDER BY f.id' ; $ db -> setQuery ( $ query ) ; $ fields = $ db -> loadObjectList ( ) ; foreach ( $ fields as $ field ) { $ csv_text .= $ field -> id . $ field_separator ; $ csv_text .= $ field -> name . $ field_separator ; $ csv_text .= $ this -> generate_csv_value ( $ field -> field_label ) . $ field_separator ; $ csv_text .= $ this -> generate_csv_value ( $ field -> field_label_message ) . $ field_separator ; $ csv_text .= $ this -> generate_csv_value ( $ field -> field_value ) . $ field_separator ; } $ csv_text .= $ message -> date_added . $ line_separator ; } } $ this -> _app -> _session -> set ( 'csv_text:' . $ this -> _sTask , $ csv_text ) ; return $ csv_text ; }
genetare the csv sting with messages
genetare the csv sting with messages
// initialize the database // read the ids of the records seleted for deletion