/** * Short description for 'validToolReg' * * Long description (if any) ... * * @param array &$tool Parameter description (if any) ... * @param array &$err Parameter description (if any) ... * @param string $id Parameter description (if any) ... * @param object $config Parameter description (if any) ... * @param integer $checker Parameter description (if any) ... * @param integer $result Parameter description (if any) ... * @return integer Return description (if any) ... */ public function validToolReg(&$tool, &$err, $id, $config, $checker = 0, $result = 1) { $tgObj = new \Components\Tools\Tables\Group($this->_db); // check if toolname exists in tool table $query = "SELECT t.id "; $query .= "FROM #__tool as t "; $query .= "WHERE t.toolname LIKE " . $this->_db->quote($tool['toolname']) . " "; if ($id) { $query .= "AND t.id!=" . $this->_db->quote($id) . " "; } $this->_db->setQuery($query); $checker = $this->_db->loadResult(); if ($checker or in_array($tool['toolname'], array('test', 'shortname', 'hub', 'tool')) && !$id) { $err['toolname'] = Lang::txt('ERR_TOOLNAME_EXISTS'); } else { if (preg_match('#^[a-zA-Z0-9]{3,15}$#', $tool['toolname']) == '' && !$id) { $err['toolname'] = Lang::txt('ERR_TOOLNAME'); } } // check if title can be used - tool table $query = "SELECT title, toolname "; $query .= "FROM #__tool "; if ($id) { $query .= "WHERE id!=" . $this->_db->quote($id) . " "; } $this->_db->setQuery($query); $rows = $this->_db->loadObjectList(); if ($rows) { for ($i = 0, $n = count($rows); $i < $n; $i++) { if (strtolower($rows[$i]->title) == strtolower($tool['title']) && $rows[$i]->toolname != $tool['toolname']) { $checker = 1; } } } $tool['toolname'] = strtolower($tool['toolname']); // make toolname lower case by default if ($checker) { // check if title exists for other tools $err['title'] = Lang::txt('ERR_TITLE_EXISTS'); } else { if ($tool['title'] == '') { $err['title'] = Lang::txt('ERR_TITLE'); } } if ($tool['description'] == '') { $err['description'] = Lang::txt('ERR_DESC'); } if ($tool['version']) { $this->validVersion($tool['toolname'], $tool['version'], $error_v, 0); if ($error_v) { $err['version'] = $error_v; } } if ($tool['exec'] == '') { $err['exec'] = Lang::txt('ERR_EXEC'); } if ($tool['exec'] == '@GROUP' && $tool['membergroups'] == '') { $err['membergroups'] = Lang::txt('ERR_GROUPS_EMPTY'); $tool['membergroups'] = array(); } else { if ($tool['membergroups'] == '' or $tool['exec'] != '@GROUP') { $tool['membergroups'] = array(); } else { if ($tool['exec'] == '@GROUP') { $tool['membergroups'] = $tgObj->writeMemberGroups($tool['membergroups'], $id, $this->_db, $error_g); if ($error_g) { $err['membergroups'] = $error_g; } } } } if ($tool['code'] == '') { $err['code'] = Lang::txt('ERR_CODE'); } if ($tool['wiki'] == '') { $err['wiki'] = Lang::txt('ERR_WIKI'); } if ($tool['developers'] == '') { $tool['developers'] = array(); $err['developers'] = Lang::txt('ERR_TEAM_EMPTY'); } else { $tool['developers'] = $tgObj->writeTeam($tool['developers'], $id, $this->_db, $error_t); if ($error_t) { $err['developers'] = $error_t; } } // format some data $vnc = isset($config->parameters['default_vnc']) ? $config->parameters['default_vnc'] : '780x600'; if ($tool['vncGeometryX'] && $tool['vncGeometryY'] && !preg_match('#[^0-9]#', $tool['vncGeometryX']) && !preg_match('#[^0-9]#', $tool['vncGeometryY'])) { $tool['vncGeometry'] = $tool['vncGeometryX'] . 'x' . $tool['vncGeometryY']; } else { $tool['vncGeometry'] = $vnc; } // return result and errors if (count($err) > 0) { $result = 0; } return $result; }