Esempio n. 1
0
 public function bind($array, $ignore = '')
 {
     if (key_exists('params', $array) && is_array($array['params'])) {
         $registry = new MRegistry();
         $registry->loadArray($array['params']);
         $array['params'] = (string) $registry;
     }
     // Attempt to bind the data.
     $return = parent::bind($array, $ignore);
     // Load the real group data based on the bound ids.
     if ($return && !empty($this->groups)) {
         // Set the group ids.
         MArrayHelper::toInteger($this->groups);
         // Get the titles for the user groups.
         $query = $this->_db->getQuery(true);
         $query->select($this->_db->quoteName('id'));
         $query->select($this->_db->quoteName('title'));
         $query->from($this->_db->quoteName('#__usergroups'));
         $query->where($this->_db->quoteName('id') . ' = ' . implode(' OR ' . $this->_db->quoteName('id') . ' = ', $this->groups));
         $this->_db->setQuery($query);
         // Set the titles for the user groups.
         $this->groups = $this->_db->loadAssocList('id', 'id');
         // Check for a database error.
         if ($this->_db->getErrorNum()) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
     }
     return $return;
 }
Esempio n. 2
0
 public function generateLayout()
 {
     list($layout, $hidden) = $this->getLayout();
     $array = array();
     $table = new MTable('table_' . $this->getId(), $this->getAttributes());
     $table->style = clone $this->style;
     $i = 0;
     $tr = array();
     foreach ($layout as $control) {
         if ($control instanceof MHContainer) {
             if ($control->checkAccess()) {
                 $mtr = new MTR();
                 $mtr->style = clone $control->style;
                 $controls = $control->getControls();
                 $j = 0;
                 $td = array();
                 $n = count($controls) - 1;
                 foreach ($controls as $content) {
                     $pos = 'cell' . $j . ($j == 0 ? ' firstCell' : ($j == $n ? ' lastCell' : ''));
                     $mtd = new MTD();
                     $mtd->setClass($pos);
                     $mtd->addControl($content);
                     $width = $content->getColumnWidth();
                     if ($width) {
                         $mtd->width = $width;
                     }
                     $td[] = $mtd;
                     $j++;
                 }
                 $mtr->addControl($td);
                 $tr[] = $mtr;
                 $i++;
             }
         }
     }
     $table->addControl($tr);
     return array($table, $hidden);
 }
Esempio n. 3
0
 public function remove()
 {
     // Check for request forgeries
     MRequest::checkToken() or jexit('Invalid Token');
     $cid = MRequest::getVar('cid', array(), '', 'array');
     MArrayHelper::toInteger($cid);
     $msg = '';
     for ($i = 0, $n = count($cid); $i < $n; $i++) {
         $query = MTable::getInstance('Query', 'Table');
         if (!$query->delete($cid[$i])) {
             $msg .= $query->getError();
             $tom = "error";
         } else {
             $msg = MTEXT::_('COM_MIWOSQL_QUERY_DELETED');
             $tom = "";
         }
     }
     $this->setRedirect('index.php?option=com_miwosql&controller=queries', $msg, $tom);
 }
Esempio n. 4
0
<?php

// no direct access to this file
defined('DACCESS') or die;
?>

<div class="m-content-header">
		<h3 class="hidden-xs hidden-sm"><span class="glyphicon glyphicon-list"></span> Pages list <small>( <a href="index.php?module=mpage&task=page_add">Add new</a> )</small></h3>
</div>

<?php 
$crumbs = array('pages' => array('title' => 'Pages'));
?>

<?php 
MHTML::breadcrumb($crumbs);
?>

<?php 
MMessaging::show();
?>

<?php 
MTable::init($data, 'pages_list');
MTable::columns(array('id', 'title', 'type', 'modified', 'enabled'));
MTable::links(array('title' => 'index.php?module=mpage&task=page_edit&object=*[id]'));
MTable::binaries(array('enabled'));
MTable::show();
?>

<script type="text/javascript">new MContent().setup_table( 'pages_list' );</script>
Esempio n. 5
0
 protected function _createTable($name, $prefix = 'Table', $config = array())
 {
     // Clean the model name
     $name = preg_replace('/[^A-Z0-9_]/i', '', $name);
     $prefix = preg_replace('/[^A-Z0-9_]/i', '', $prefix);
     // Make sure we are returning a DBO object
     if (!array_key_exists('dbo', $config)) {
         $config['dbo'] = $this->getDbo();
     }
     return MTable::getInstance($name, $prefix, $config);
 }
Esempio n. 6
0
 public function __construct(&$db)
 {
     parent::__construct('#__miwosql_queries', 'id', $db);
 }
Esempio n. 7
0
/**
* @package		MiwoSQL
* @copyright	2009-2012 Mijosoft LLC, www.mijosoft.com
* @license		GNU/GPL http://www.gnu.org/copyleft/gpl.html
*/
// no direct access
defined('MIWI') or die('Restricted access');
if (version_compare(MVERSION, '1.6.0', 'ge')) {
    if (!MFactory::getUser()->authorise('core.manage', 'com_miwosql')) {
        return MError::raiseWarning(404, MText::_('MERROR_ALERTNOAUTHOR'));
    }
}
require_once MPATH_COMPONENT . '/mvc/model.php';
require_once MPATH_COMPONENT . '/mvc/view.php';
require_once MPATH_COMPONENT . '/mvc/controller.php';
require_once MPATH_COMPONENT . '/toolbar.php';
require_once MPATH_COMPONENT . '/helpers/helper.php';
MTable::addIncludePath(MPATH_COMPONENT . '/tables');
if ($controller = MRequest::getWord('controller')) {
    $path = MPATH_COMPONENT . '/controllers/' . $controller . '.php';
    if (file_exists($path)) {
        require_once $path;
    } else {
        $controller = '';
    }
}
$classname = 'MiwosqlController' . ucfirst($controller);
$controller = new $classname();
$controller->execute(MRequest::getCmd('task'));
$controller->redirect();
echo '<div style="margin: 10px; text-align: center;"><a href="http://miwisoft.com/wordpress-plugins/miwosql" target="_blank">MiwoSQL | Copyright &copy; 2009-2014 Miwisoft LLC</a></div>';
Esempio n. 8
0
 function saveQuery($post)
 {
     $row = MTable::getInstance('Query', 'Table');
     // Bind the form fields to the web link table
     if (!$row->bind($post)) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // Make sure the web link table is valid
     if (!$row->check()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // Store the web link table to the database
     if (!$row->store()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     return true;
     return;
 }
Esempio n. 9
0
 public function store($updateNulls = false)
 {
     $k = $this->_tbl_key;
     if ($this->_debug) {
         echo "\n" . get_class($this) . "::store\n";
         $this->_logtable(true, false);
     }
     if (empty($this->{$k})) {
         if ($this->_location_id >= 0) {
             if (!$this->_lock()) {
                 return false;
             }
             if ($this->_location_id == 0) {
                 $query = $this->_db->getQuery(true);
                 $query->select($this->_tbl_key . ', parent_id, level, lft, rgt');
                 $query->from($this->_tbl);
                 $query->where('parent_id = 0');
                 $query->order('lft DESC');
                 $this->_db->setQuery($query, 0, 1);
                 $reference = $this->_db->loadObject();
                 if ($this->_db->getErrorNum()) {
                     $e = new MException(MText::sprintf('MLIB_DATABASE_ERROR_STORE_FAILED', get_class($this), $this->_db->getErrorMsg()));
                     $this->setError($e);
                     $this->_unlock();
                     return false;
                 }
                 if ($this->_debug) {
                     $this->_logtable(false);
                 }
             } else {
                 if (!($reference = $this->_getNode($this->_location_id))) {
                     $this->_unlock();
                     return false;
                 }
             }
             if (!($repositionData = $this->_getTreeRepositionData($reference, 2, $this->_location))) {
                 $this->_unlock();
                 return false;
             }
             $query = $this->_db->getQuery(true);
             $query->update($this->_tbl);
             $query->set('lft = lft + 2');
             $query->where($repositionData->left_where);
             $this->_runQuery($query, 'MLIB_DATABASE_ERROR_STORE_FAILED');
             $query = $this->_db->getQuery(true);
             $query->update($this->_tbl);
             $query->set('rgt = rgt + 2');
             $query->where($repositionData->right_where);
             $this->_runQuery($query, 'MLIB_DATABASE_ERROR_STORE_FAILED');
             $this->parent_id = $repositionData->new_parent_id;
             $this->level = $repositionData->new_level;
             $this->lft = $repositionData->new_lft;
             $this->rgt = $repositionData->new_rgt;
         } else {
             $e = new MException(MText::_('MLIB_DATABASE_ERROR_INVALID_PARENT_ID'));
             $this->setError($e);
             return false;
         }
     } else {
         if ($this->_location_id > 0) {
             if (!$this->moveByReference($this->_location_id, $this->_location, $this->{$k})) {
                 return false;
             }
         }
         if (!$this->_lock()) {
             return false;
         }
     }
     if (!parent::store($updateNulls)) {
         $this->_unlock();
         return false;
     }
     if ($this->_debug) {
         $this->_logtable();
     }
     $this->_unlock();
     return true;
 }
Esempio n. 10
0
 protected function batchMove($value, $pks, $contexts)
 {
     $categoryId = (int) $value;
     $table = $this->getTable();
     // Check that the category exists
     if ($categoryId) {
         $categoryTable = MTable::getInstance('Category');
         if (!$categoryTable->load($categoryId)) {
             if ($error = $categoryTable->getError()) {
                 // Fatal error
                 $this->setError($error);
                 return false;
             } else {
                 $this->setError(MText::_('MLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND'));
                 return false;
             }
         }
     }
     if (empty($categoryId)) {
         $this->setError(MText::_('MLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND'));
         return false;
     }
     // Check that user has create and edit permission for the component
     $extension = MFactory::getApplication()->input->get('option', '');
     $user = MFactory::getUser();
     if (!$user->authorise('core.create', $extension . '.category.' . $categoryId)) {
         $this->setError(MText::_('MLIB_APPLICATION_ERROR_BATCH_CANNOT_CREATE'));
         return false;
     }
     // Parent exists so we let's proceed
     foreach ($pks as $pk) {
         if (!$user->authorise('core.edit', $contexts[$pk])) {
             $this->setError(MText::_('MLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
             return false;
         }
         // Check that the row actually exists
         if (!$table->load($pk)) {
             if ($error = $table->getError()) {
                 // Fatal error
                 $this->setError($error);
                 return false;
             } else {
                 // Not fatal error
                 $this->setError(MText::sprintf('MLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk));
                 continue;
             }
         }
         // Set the new category ID
         $table->catid = $categoryId;
         // Check the row.
         if (!$table->check()) {
             $this->setError($table->getError());
             return false;
         }
         // Store the row.
         if (!$table->store()) {
             $this->setError($table->getError());
             return false;
         }
     }
     // Clean the cache
     $this->cleanCache();
     return true;
 }
Esempio n. 11
0
 public static function checkedOut(&$row, $i, $identifier = 'id')
 {
     $user = MFactory::getUser();
     $userid = $user->get('id');
     $result = false;
     if ($row instanceof MTable) {
         $result = $row->isCheckedOut($userid);
     } else {
         $result = MTable::isCheckedOut($userid, $row->checked_out);
     }
     $checked = '';
     if ($result) {
         $checked = MHtmlGrid::_checkedOut($row);
     } else {
         if ($identifier == 'id') {
             $checked = MHtml::_('grid.id', $i, $row->{$identifier});
         } else {
             $checked = MHtml::_('grid.id', $i, $row->{$identifier}, $result, $identifier);
         }
     }
     return $checked;
 }
Esempio n. 12
0
 public function delete($pk = null)
 {
     // Initialise variables.
     $k = $this->_tbl_key;
     $pk = is_null($pk) ? $this->{$k} : $pk;
     // If no primary key is given, return false.
     if ($pk === null) {
         $e = new MException(MText::_('MLIB_DATABASE_ERROR_NULL_PRIMARY_KEY'));
         $this->setError($e);
         return false;
     }
     // If tracking assets, remove the asset first.
     if ($this->_trackAssets) {
         // Get and the asset name.
         $this->{$k} = $pk;
         $name = $this->_getAssetName();
         $asset = MTable::getInstance('Asset');
         if ($asset->loadByName($name)) {
             if (!$asset->delete()) {
                 $this->setError($asset->getError());
                 return false;
             }
         } else {
             $this->setError($asset->getError());
             return false;
         }
     }
     // Delete the row by primary key.
     $query = $this->_db->getQuery(true);
     $query->delete();
     $query->from($this->_tbl);
     $query->where($this->_tbl_key . ' = ' . $this->_db->quote($pk));
     $this->_db->setQuery($query);
     // Check for a database error.
     if (!$this->_db->execute()) {
         $e = new MException(MText::sprintf('MLIB_DATABASE_ERROR_DELETE_FAILED', get_class($this), $this->_db->getErrorMsg()));
         $this->setError($e);
         return false;
     }
     return true;
 }
Esempio n. 13
0
 static function show()
 {
     if (!self::$init) {
         return null;
     }
     self::table_head();
     self::table_body();
     self::table_foot();
     self::$init = null;
 }