protected function _execute(InputInterface $input, OutputInterface $output) { $group = $input->getArgument('group'); $labelkey = $input->getArgument('labelkey'); $label = $input->getArgument('label'); $cnx = \jDb::getConnection('jacl2_profile'); $sql = "SELECT id_aclsbjgrp FROM " . $cnx->prefixTable('jacl2_subject_group') . " WHERE id_aclsbjgrp=" . $cnx->quote($group); $rs = $cnx->query($sql); if ($rs->fetch()) { throw new \Exception("This subject group already exists"); } $sql = "INSERT into " . $cnx->prefixTable('jacl2_subject_group') . " (id_aclsbjgrp, label_key) VALUES ("; $sql .= $cnx->quote($group) . ','; $sql .= $cnx->quote($labelkey); $sql .= ')'; $cnx->exec($sql); if ($this->verbose()) { $ouput->writeln("Rights: group of subjects '" . $group . "' is created"); } if ($label && preg_match("/^([a-zA-Z0-9_\\.]+)~([a-zA-Z0-9_]+)\\.([a-zA-Z0-9_\\.]+)\$/", $labelkey, $m)) { $localestring = "\n" . $m[3] . '=' . $label; $path = $this->getModulePath($m[1]); $file = $path . 'locales/' . \jApp::config()->locale . '/' . $m[2] . '.' . \jApp::config()->charset . '.properties'; if (file_exists($file)) { $localestring = file_get_contents($file) . $localestring; } file_put_contents($file, $localestring); if ($output->isVerbose()) { $output->writeln("locale string " . $m[3] . " is created into " . $file); } } }
/** * action to process the page after the submit * @return 0 */ function process() { $errors = array(); $login = $_SESSION['adminaccount']['login'] = trim($_POST['login']); if ($login == '') { $errors[] = $this->locales['error.missing.login']; } $password = $_SESSION['adminaccount']['password'] = trim($_POST['password']); if ($password == '') { $errors[] = $this->locales['error.missing.password']; } $passwordconf = $_SESSION['adminaccount']['password_confirm'] = trim($_POST['password_confirm']); if ($password != $passwordconf) { $errors[] = $this->locales['error.confirm.password']; } $email = $_SESSION['adminaccount']['email'] = trim($_POST['email']); if ($email == '') { $errors[] = $this->locales['error.missing.email']; } if (count($errors)) { $_SESSION['adminaccount']['errors'] = $errors; return false; } jApp::loadConfig('havefnubb/config.ini.php'); $db = jDb::getConnection(); $db->exec('INSERT INTO ' . $db->encloseName($db->prefixTable('community_users')) . ' (login, password, email, nickname, status, create_date) VALUES (' . $db->quote($login) . ',' . $db->quote(md5($password)) . ',' . $db->quote($email) . ',' . $db->quote($login) . ',1,' . "'" . date('Y-m-d H:i:s') . "')"); $idu = $db->lastInsertId(); $db->exec('INSERT INTO ' . $db->encloseName($db->prefixTable('jacl2_group')) . ' (id_aclgrp, name, grouptype, ownerlogin) ' . 'VALUES (' . $db->quote('__priv_' . $login) . ',' . $db->quote($login) . ',2,' . $db->quote($login) . ')'); $db->exec('INSERT INTO ' . $db->encloseName($db->prefixTable('jacl2_user_group')) . ' (login, id_aclgrp) VALUES (' . $db->quote($login) . ',\'admins\')'); $db->exec('INSERT INTO ' . $db->encloseName($db->prefixTable('jacl2_user_group')) . ' (login, id_aclgrp) VALUES (' . $db->quote($login) . ',' . $db->quote('__priv_' . $login) . ')'); unset($_SESSION['adminaccount']); return 0; }
protected function _execute(InputInterface $input, OutputInterface $output) { $group = $input->getArgument('group'); $name = $input->getArgument('name'); $isDefault = $input->getOption('default'); if (!$name) { $name = $group; } $cnx = \jDb::getConnection('jacl2_profile'); try { $sql = "INSERT into " . $cnx->prefixTable('jacl2_group') . " (id_aclgrp, name, grouptype, ownerlogin) VALUES ("; $sql .= $cnx->quote($group) . ','; $sql .= $cnx->quote($name) . ','; if ($isDefault) { $sql .= '1, NULL)'; } else { $sql .= '0, NULL)'; } $cnx->exec($sql); } catch (\Exception $e) { throw new \Exception("this group already exists"); } if ($output->isVerbose()) { $output->writeln("Group '" . $group . "' is created"); } }
protected function _execute(InputInterface $input, OutputInterface $output) { $subject = $input->getArgument('subject'); $cnx = \jDb::getConnection('jacl2_profile'); if (!$input->getOption('confirm')) { $helper = $this->getHelper('question'); $question = new ConfirmationQuestion('are you sure you want to delete subject ' . $subject . ' (y/N)?', false); if (!$helper->ask($input, $output, $question)) { $output->writeln('command canceled'); return; } } $sql = "SELECT id_aclsbj FROM " . $cnx->prefixTable('jacl2_subject') . " WHERE id_aclsbj=" . $cnx->quote($subject); $rs = $cnx->query($sql); if (!$rs->fetch()) { throw new \Exception("This subject does not exist"); } $sql = "DELETE FROM " . $cnx->prefixTable('jacl2_rights') . " WHERE id_aclsbj="; $sql .= $cnx->quote($subject); $cnx->exec($sql); $sql = "DELETE FROM " . $cnx->prefixTable('jacl2_subject') . " WHERE id_aclsbj="; $sql .= $cnx->quote($subject); $cnx->exec($sql); if ($output->isVerbose()) { $output->writeln("Rights: subject " . $subject . " is deleted"); } }
protected function _execute(InputInterface $input, OutputInterface $output) { $cnx = \jDb::getConnection('jacl2_profile'); $table = new Table($output); $groupFiler = false; if ($input->getArgument('group')) { $id = $this->_getGrpId($input, true); $sql = "SELECT login FROM " . $cnx->prefixTable('jacl2_user_group') . " WHERE id_aclgrp =" . $cnx->quote($id); $table->setHeaders(array('Login')); $groupFiler = true; } else { $sql = "SELECT login, g.id_aclgrp, name FROM " . $cnx->prefixTable('jacl2_user_group') . " AS u " . " LEFT JOIN " . $cnx->prefixTable('jacl2_group') . " AS g\n ON (u.id_aclgrp = g.id_aclgrp AND g.grouptype < 2)\n ORDER BY login"; $table->setHeaders(array('Login', 'group', 'group id')); } $cnx = \jDb::getConnection('jacl2_profile'); $rs = $cnx->query($sql); foreach ($rs as $rec) { if ($groupFiler) { $table->addRow(array($rec->login)); } else { $table->addRow(array($rec->login, $rec->name, $rec->id_aclgrp)); } } $table->render(); }
protected function _execute(InputInterface $input, OutputInterface $output) { $cnx = \jDb::getConnection('jacl2_profile'); $group = $cnx->quote($this->_getGrpId($input)); $subject = $cnx->quote($input->getArgument('subject')); $resource = $cnx->quote($input->getArgument('resource')); $sql = "SELECT * FROM " . $cnx->prefixTable('jacl2_rights') . "\n WHERE id_aclgrp=" . $group . "\n AND id_aclsbj=" . $subject . "\n AND id_aclres=" . $resource; $rs = $cnx->query($sql); if ($rs->fetch()) { throw new \Exception("right already set"); } $sql = "SELECT * FROM " . $cnx->prefixTable('jacl2_subject') . " WHERE id_aclsbj=" . $subject; $rs = $cnx->query($sql); if (!($sbj = $rs->fetch())) { throw new \Exception("subject is unknown"); } $sql = "INSERT into " . $cnx->prefixTable('jacl2_rights') . " (id_aclgrp, id_aclsbj, id_aclres) VALUES ("; $sql .= $group . ','; $sql .= $subject . ','; $sql .= $resource . ')'; $cnx->exec($sql); if ($output->isVerbose()) { $output->writeln("Right is added on subject {$subject} with group {$group} and resource {$resource}"); } }
/** * get the Rate of a given source and ID * @param integer $id_source the id to link to the source * @param string $source the linked source * @return integer $total the global rate */ function getTotalRatesBySource($id_source, $source) { $cnx = jDb::getConnection(); $strQuery = 'SELECT COUNT(*) as total_rates, SUM(level) as total_level, AVG(level) as avg_level ' . ' FROM ' . $cnx->prefixTable('hfnu_rates') . " WHERE id_source = '" . $id_source . "' AND source='" . addslashes($source) . "' GROUP BY id_source"; $rs = $cnx->query($strQuery); $total = $rs->fetch(); return $total; }
/** * */ function index() { $rep = $this->getResponse('html'); $groups = array(); $o = new StdClass(); $o->id_aclgrp = '-2'; $o->name = jLocale::get('jacl2_admin~acl2.all.users.option'); $o->grouptype = 0; $groups[] = $o; $o = new StdClass(); $o->id_aclgrp = '-1'; $o->name = jLocale::get('jacl2_admin~acl2.without.groups.option'); $o->grouptype = 0; $groups[] = $o; foreach (jAcl2DbUserGroup::getGroupList() as $grp) { $groups[] = $grp; } $listPageSize = 15; $offset = $this->intParam('idx', 0, true); $grpid = $this->intParam('grpid', -2, true); $p = jAcl2Db::getProfil(); if ($grpid == -2) { //all users $dao = jDao::get('jelix~jacl2groupsofuser', $p); $cond = jDao::createConditions(); $cond->addCondition('grouptype', '=', 2); $rs = $dao->findBy($cond, $offset, $listPageSize); $usersCount = $dao->countBy($cond); } elseif ($grpid == -1) { //only those who have no groups $sql = 'SELECT login, count(id_aclgrp) as nbgrp FROM jacl2_user_group GROUP BY login HAVING nbgrp < 2 ORDER BY login'; $cnx = jDb::getConnection($p); $rs = $cnx->query($sql); $usersCount = -1; } else { //in a specific group $dao = jDao::get('jelix~jacl2usergroup', $p); $rs = $dao->getUsersGroupLimit($grpid, $offset, $listPageSize); $usersCount = $dao->getUsersGroupCount($grpid); } $users = array(); $dao2 = jDao::get('jelix~jacl2groupsofuser', $p); foreach ($rs as $u) { $u->groups = array(); $gl = $dao2->getGroupsUser($u->login); foreach ($gl as $g) { if ($g->grouptype != 2) { $u->groups[] = $g; } } $users[] = $u; } $tpl = new jTpl(); $tpl->assign(compact('offset', 'grpid', 'listPageSize', 'groups', 'users', 'usersCount')); $rep->body->assign('MAIN', $tpl->fetch('users_list')); return $rep; }
public function run() { $this->loadAppConfig(); $module = $this->_parameters['module']; $path = $this->getModulePath($module); $filename = $path . 'daos/'; $this->createDir($filename); $daofile = strtolower($this->_parameters['name']) . '.dao.xml'; $filename .= $daofile; $profile = $this->getOption('-profile'); $param = array('name' => $this->_parameters['name'], 'table' => $this->getParam('table')); if ($param['table'] == null) { $param['table'] = $param['name']; } if ($this->getOption('-empty')) { $this->createFile($filename, 'module/dao_empty.xml.tpl', $param, "Empty DAO"); } else { $sequence = $this->getParam('sequence', ''); $tools = jDb::getConnection($profile)->tools(); $fields = $tools->getFieldList($param['table'], $sequence); $properties = ''; $primarykeys = ''; foreach ($fields as $fieldname => $prop) { $name = str_replace('-', '_', $fieldname); $properties .= "\n <property name=\"{$name}\" fieldname=\"{$fieldname}\""; $properties .= ' datatype="' . $prop->type . '"'; if ($prop->primary) { if ($primarykeys != '') { $primarykeys .= ',' . $fieldname; } else { $primarykeys .= $fieldname; } } if ($prop->notNull && !$prop->autoIncrement) { $properties .= ' required="true"'; } if ($prop->autoIncrement) { $properties .= ' autoincrement="true"'; } if ($prop->hasDefault) { $properties .= ' default="' . htmlspecialchars($prop->default) . '"'; } if ($prop->length) { $properties .= ' maxlength="' . $prop->length . '"'; } if ($prop->sequence) { $properties .= ' sequence="' . $prop->sequence . '"'; } $properties .= '/>'; } if ($primarykeys == '') { throw new Exception("The table " . $param['table'] . " has no primary keys. A dao needs a primary key on the table to be defined."); } $param['properties'] = $properties; $param['primarykeys'] = $primarykeys; $this->createFile($filename, 'module/dao.xml.tpl', $param, "DAO"); } }
protected function _connect() { if (!isset($this->_profile['table']) || !isset($this->_profile['dbprofile'])) { throw new Exception("table and dbprofile is missing for the db kvdb driver"); } $this->table = $this->_profile['table']; $cnx = jDb::getConnection($this->_profile['dbprofile']); return $cnx; }
function testTableList() { $db = jDb::getConnection(); $tools = new testmysqlDbTools($db); $goodList = array('jacl_group', 'jacl_right_values', 'jacl_right_values_group', 'jacl_rights', 'jacl_subject', 'jacl_user_group', 'jacl2_group', 'jacl2_user_group', 'jacl2_subject', 'jacl2_subject_group', 'jacl2_rights', 'jlx_user', 'myconfig', 'product_test', 'product_tags_test', 'labels_test', 'labels1_test', 'products', 'jlx_cache', 'jsessions', 'testkvdb'); $list = $tools->getTableList(); sort($goodList); sort($list); $this->assertEqual($list, $goodList); }
/** * import a sql script into the given profile. * * The name of the script should be store in install/sql/$name.databasetype.sql * in the directory of the component. (replace databasetype by mysql, pgsql etc.) * * @param string $name the name of the script, without suffixes */ public function execSQLScript($name, $profile = '') { $tools = jDb::getTools($profile); $p = jDb::getProfile($profile); $driver = $p['driver']; if ($driver == 'pdo') { preg_match('/^(\\w+)\\:.*$/', $p['dsn'], $m); $driver = $m[1]; } $tools->execSQLScript($this->path . 'install/sql/' . $name . '.' . $driver . '.sql'); }
protected function _execute(InputInterface $input, OutputInterface $output) { $group = $input->getArgument('group'); $login = $input->getArgument('login'); $cnx = \jDb::getConnection('jacl2_profile'); $groupid = $this->_getGrpId($input); $sql = "DELETE FROM " . $cnx->prefixTable('jacl2_user_group') . " WHERE login="******" AND id_aclgrp=" . $cnx->quote($groupid); $cnx->exec($sql); if ($output->isVerbose()) { $output->writeln("User '" . $login . "' is removed from group '" . $group . "'"); } }
protected function _execute(InputInterface $input, OutputInterface $output) { $table = new Table($output); $table->setHeaders(array('id', 'label key')); $cnx = \jDb::getConnection('jacl2_profile'); $sql = "SELECT id_aclsbjgrp, label_key FROM " . $cnx->prefixTable('jacl2_subject_group') . " ORDER BY id_aclsbjgrp"; $rs = $cnx->query($sql); foreach ($rs as $rec) { $table->addRow(array($rec->id_aclsbjgrp, $rec->label_key)); } $table->render(); }
protected function _execute(InputInterface $input, OutputInterface $output) { $group = $input->getArgument('group'); $def = $input->getOption('no-default') ? 0 : 1; $id = $this->_getGrpId($input, true); $cnx = \jDb::getConnection('jacl2_profile'); $sql = "UPDATE " . $cnx->prefixTable('jacl2_group') . " SET grouptype={$def} WHERE id_aclgrp=" . $cnx->quote($id); $cnx->exec($sql); if ($output->isVerbose()) { $output->writeln("Group '" . $group . "' is " . ($def ? ' now a default group' : ' no more a default group')); } }
protected function _execute(InputInterface $input, OutputInterface $output) { $table = new Table($output); $table->setHeaders(array('Subject Group', 'id', 'label key')); $cnx = \jDb::getConnection('jacl2_profile'); $sql = "SELECT id_aclsbj, s.label_key, s.id_aclsbjgrp, g.label_key as group_label_key FROM " . $cnx->prefixTable('jacl2_subject') . " s\n LEFT JOIN " . $cnx->prefixTable('jacl2_subject_group') . " g\n ON (s.id_aclsbjgrp = g.id_aclsbjgrp)\n ORDER BY s.id_aclsbjgrp, id_aclsbj"; $rs = $cnx->query($sql); foreach ($rs as $rec) { $table->addRow(array($rec->id_aclsbjgrp, $rec->id_aclsbj, $rec->label_key)); } $table->render(); }
public static function create($DaoId, $profile = '') { if (is_string($DaoId)) { $DaoId = new jSelectorDao($DaoId, $profile); } $c = $DaoId->getDaoClass(); if (!class_exists($c, false)) { jIncluder::inc($DaoId); } $conn = jDb::getConnection($profile); $obj = new $c($conn); return $obj; }
/** * return the profile name used for jacl connection * @return string profile name */ public static function getProfile() { static $profile = ''; if ($profile == '') { try { $prof = jDb::getProfile('jacl_profile', true); } catch (Exception $e) { $prof = jDb::getProfile(); } $profile = $prof['name']; } return $profile; }
/** * */ function search() { $localConfig = jApp::configPath('localconfig.ini.php'); $ini = new jIniFileModifier($localConfig); $jdbParams = array("driver" => $ini->getValue('db_driver', 'localiz_plugin') ?: 'pgsql', "host" => $ini->getValue('db_host', 'localiz_plugin'), "port" => $ini->getValue('db_port', 'localiz_plugin') ?: 5432, "database" => $ini->getValue('db_database', 'localiz_plugin'), "user" => $ini->getValue('db_user', 'localiz_plugin') ?: 'postgres', "password" => $ini->getValue('db_password', 'localiz_plugin')); jProfiles::createVirtualProfile('jdb', 'localiz_plugin', $jdbParams); $cnx = jDb::getConnection('localiz_plugin'); $sql = sprintf($ini->getValue('db_query', 'localiz_plugin'), $this->param('term')); $res = $cnx->query($sql); $rep = $this->getResponse('json'); $rep->data = array(); foreach ($res as $record) { $rep->data[] = array('oid' => $record->oid, 'typcode' => $record->typcode, 'value' => $record->value, 'label' => $record->label, 'longlabel' => $record->longlabel, 'geometrytype' => $record->geometrytype, 'xmin' => $record->xmin, 'ymin' => $record->ymin, 'xmax' => $record->xmax, 'ymax' => $record->ymax); } return $rep; }
function __construct($sel, $driver, $isprofile = true) { if ($isprofile) { $p = jDb::getProfile($driver); if ($p['driver'] == 'pdo') { $this->driver = substr($p['dsn'], 0, strpos($p['dsn'], ':')); } else { $this->driver = $p['driver']; } } else { $this->driver = $driver; } $this->_compiler = 'jDaoCompiler'; $this->_compilerPath = JELIX_LIB_PATH . 'dao/jDaoCompiler.class.php'; parent::__construct($sel); }
protected function _execute(InputInterface $input, OutputInterface $output) { $table = new Table($output); $table->setHeaders(array('Id', 'label', 'default')); $cnx = \jDb::getConnection('jacl2_profile'); $sql = "SELECT id_aclgrp, name, grouptype FROM " . $cnx->prefixTable('jacl2_group') . " WHERE grouptype <2 ORDER BY name"; $rs = $cnx->query($sql); foreach ($rs as $rec) { if ($rec->grouptype == 1) { $type = 'yes'; } else { $type = ''; } $table->addRow(array($rec->id_aclgrp, $rec->name, $type)); } $table->render(); }
protected function _execute(InputInterface $input, OutputInterface $output) { $cnx = \jDb::getConnection('jacl2_profile'); $sql = "SELECT r.id_aclgrp, r.id_aclsbj, r.id_aclres, s.label_key as subject\n FROM " . $cnx->prefixTable('jacl2_rights') . " r,\n " . $cnx->prefixTable('jacl2_subject') . " s\n WHERE r.id_aclgrp = '__anonymous' AND r.id_aclsbj=s.id_aclsbj\n ORDER BY subject, id_aclres "; $rs = $cnx->query($sql); $table = new Table($output); $table->setHeaders(array('Group id', 'Group name', 'Subject', 'Resource')); foreach ($rs as $rec) { $table->addRow(array('Anonymous', $rec->id_aclsbj, $rec->id_aclres)); } $sql = "SELECT r.id_aclgrp, r.id_aclsbj, r.id_aclres, name as grp, s.label_key as subject\n FROM " . $cnx->prefixTable('jacl2_rights') . " r,\n " . $cnx->prefixTable('jacl2_group') . " g,\n " . $cnx->prefixTable('jacl2_subject') . " s\n WHERE r.id_aclgrp = g.id_aclgrp AND r.id_aclsbj=s.id_aclsbj\n ORDER BY grp, subject, id_aclres "; $rs = $cnx->query($sql); foreach ($rs as $rec) { $table->addRow(array($rec->id_aclgrp, $rec->grp, $rec->id_aclsbj, $rec->id_aclres)); } $table->render(); }
public function getDatasourceConnection() { $dtParams = $this->getDatasourceParameters(); $jdbParams = array(); if ($this->provider == 'spatialite') { $repository = $this->project->getRepository(); $jdbParams = array("driver" => 'sqlite3', "database" => realpath($repository->getPath() . $dtParams->dbname), "extensions" => "libspatialite.so"); } else { if ($this->provider == 'postgres') { $jdbParams = array("driver" => 'pgsql', "host" => $dtParams->host, "port" => (int) $dtParams->port, "database" => $dtParams->dbname, "user" => $dtParams->user, "password" => $dtParams->password); } else { return null; } } $profile = $this->id; jProfiles::createVirtualProfile('jdb', $profile, $jdbParams); return jDb::getConnection($profile); }
function testTools() { try { $profile = jProfiles::get('jdb', 'testapp_sqlite', true); } catch (Exception $e) { $this->sendMessage("UTjDbSqlite cannot be run : no sqlite profile"); return; } $tools = jDb::getConnection('testapp_sqlite')->tools(); $fields = $tools->getFieldList('products'); $structure = '<array> <object key="id" class="jDbFieldProperties"> <string property="type" value="integer" /> <string property="name" value="id" /> <boolean property="notNull" value="true" /> <boolean property="primary" value="true" /> <boolean property="autoIncrement" value="true" /> <boolean property="hasDefault" value="false" /> <string property="default" value="" /> <integer property="length" value="0" /> </object> <object key="name" class="jDbFieldProperties"> <string property="type" value="varchar" /> <string property="name" value="name" /> <boolean property="notNull" value="true" /> <boolean property="primary" value="false" /> <boolean property="autoIncrement" value="false" /> <boolean property="hasDefault" value="false" /> <string property="default" value="" /> <integer property="length" value="150" /> </object> <object key="price" class="jDbFieldProperties"> <string property="type" value="float" /> <string property="name" value="price" /> <boolean property="notNull" value="false" /> <boolean property="primary" value="false" /> <boolean property="autoIncrement" value="false" /> <boolean property="hasDefault" value="true" /> <string property="default" value="0" /> <integer property="length" value="0" /> </object> </array>'; $this->assertComplexIdenticalStr($fields, $structure, 'bad results'); }
public static function check($alias) { $cnx = jDb::getConnection(); $user = jAuth::getUserSession(); try { //informations de connection profile DB $sql = "SELECT COUNT(F.id) AS total FROM " . $cnx->prefixTable('user') . " U\n RIGHT JOIN " . $cnx->prefixTable('user_group') . " UG ON U.id = UG.user_id\n RIGHT JOIN " . $cnx->prefixTable('group_feature') . " GF ON UG.group_id = GF.group_id\n RIGHT JOIN " . $cnx->prefixTable('feature') . " F ON GF.feature_id = F.id\n WHERE UG.user_id = '" . $user->id . "' AND (F.title = '" . $alias . "' OR F.title = '*') "; $rs = $cnx->query($sql); $record = $rs->fetch(); if ($record->total >= 1) { $result = true; } else { $result = false; } return $result; } catch (Exception $e) { throw new Exception($e); } }
/** * Size of the database * @return array the total size and record of the database */ public static function dbSize() { $profile = jDb::getProfile(); $con = jDb::getConnection(); $totalRecords = $totalSize = 0; if ($profile['driver'] == 'mysql' or $profile['driver'] == 'mysqli') { $results = $con->query('SHOW TABLE STATUS FROM `' . $profile['database'] . '`'); foreach ($results as $status) { $totalRecords += $status->Rows; $totalSize += $status->Data_length + $status->Index_length; } $totalSize = $totalSize / 1024; if ($totalSize > 1024) { $totalSize = round($totalSize / 1024, 2) . ' MB'; } else { $totalSize = round($totalSize, 2) . ' KB'; } } return array($totalRecords, $totalSize); }
protected function _execute(InputInterface $input, OutputInterface $output) { $login = $input->getArgument('login'); $cnx = \jDb::getConnection('jacl2_profile'); $loginq = $cnx->quote($login); $sql = "SELECT * FROM " . $cnx->prefixTable('jacl2_user_group') . " WHERE login = {$loginq}"; $rs = $cnx->query($sql); if ($rec = $rs->fetch()) { throw new \Exception("the user is already registered"); } $groupid = $cnx->quote('__priv_' . $login); $sql = "INSERT into " . $cnx->prefixTable('jacl2_group') . " (id_aclgrp, name, grouptype, ownerlogin) VALUES ("; $sql .= $groupid . ',' . $loginq . ',2, ' . $loginq . ')'; $cnx->exec($sql); $sql = "INSERT INTO " . $cnx->prefixTable('jacl2_user_group') . " (login, id_aclgrp) VALUES(" . $loginq . ", " . $groupid . ")"; $cnx->exec($sql); if ($output->isVerbose()) { $output->writeln("user {$login} is added into rights system and has a private group {$groupid}"); } }
function testFloatToStr() { $this->assertEqual('12', jDb::floatToStr(12)); $this->assertEqual('12.56', jDb::floatToStr(12.56)); $this->assertEqual('12', jDb::floatToStr("12")); $this->assertEqual('12.56', jDb::floatToStr("12.56")); $this->assertEqual('65.78E6', jDb::floatToStr("65.78E6")); $this->assertEqual('65.78E6', jDb::floatToStr(65780000.0)); $this->assertEqual('65.78E42', jDb::floatToStr(6.578E+43)); // not very good behavior, but this is the behavior in old stable version of jelix $this->assertEqual('65', jDb::floatToStr("65,650.98")); $this->assertEqual('12', jDb::floatToStr("12,589")); // ',' no allowed as decimal separator $this->assertEqual('96', jDb::floatToStr("96 000,98")); // some test to detect if the behavior of PHP change $this->assertFalse(is_numeric("65,650.98")); $this->assertFalse(is_float("65,650.98")); $this->assertFalse(is_integer("65,650.98")); $this->assertEqual('65', floatval("65,650.98")); }
protected function _execute(InputInterface $input, OutputInterface $output) { $login = $input->getArgument('login'); if (!$input->getOption('confirm')) { $helper = $this->getHelper('question'); $question = new ConfirmationQuestion('Are you sure you want to unregister user ' . $login . ' from rights system (y/N)?', false); if (!$helper->ask($input, $output, $question)) { $output->writeln('command canceled'); return; } } $cnx = \jDb::getConnection('jacl2_profile'); $sql = "DELETE FROM " . $cnx->prefixTable('jacl2_group') . " WHERE grouptype=2 and ownerlogin="******"DELETE FROM " . $cnx->prefixTable('jacl2_user_group') . " WHERE login="******"User '" . $login . "' is unregistered from rights system."); } }
protected function _getGrpId(InputInterface $input, $onlypublic = false) { $param = $input->getArgument('group'); if ($param == '__anonymous') { return $param; } if ($onlypublic) { $c = ' grouptype <2 AND '; } else { $c = ''; } $cnx = \jDb::getConnection('jacl2_profile'); $sql = "SELECT id_aclgrp FROM " . $cnx->prefixTable('jacl2_group') . " WHERE {$c} "; $sql .= " id_aclgrp = " . $cnx->quote($param); $rs = $cnx->query($sql); if ($rec = $rs->fetch()) { return $rec->id_aclgrp; } else { throw new \Exception("this group doesn't exist or is private"); } }