public function testCheckFields() { $goodCategory = 'todo'; $badCategory = 'unknowcategory'; $goodUser = '******'; $badUser = '******'; // check good values $this->assertTrue(checkFields($goodCategory, 'mybesttitle', $goodUser, $goodUser, 'desc')); // check bad category $this->assertFalse(checkFields($badCategory, 'mybesttitle', $goodUser, $goodUser, 'desc')); // check bad title $this->assertFalse(checkFields($goodCategory, '', $goodUser, $goodUser, 'desc')); // check bad user $this->assertFalse(checkFields($goodCategory, 'mybesttitle', $badUser, $badUser, 'desc')); }
function updateTask($category, $title, $editor, $affectedUser, $description, $id) { // read global var $app global $app; // check user permission exists if (checkUserPermission($editor, "editTask") == true) { //check fields $owner = $app['tasks'][$id]['owner']; // same as before if (checkFields($category, $title, $owner, $affectedUser, $description)) { //update tasks in global array $app['tasks'][$id] = array('category' => $category, 'title' => $title, 'owner' => $owner, 'affectedUser' => $affectedUser, 'description' => $description); saveTasks(); } else { throw new Exception("One or many fields are invalid!", 2); } } else { throw new Exception("Permission denied!", 1); } }
function doStage2() { if (doSystemChecks()) { displayWarnings(); if (checkFields()) { if (checkConfigFiles()) { if (doInstall()) { return true; } } } displayErrors(); displayFields(); } else { displayErrors(); } return false; }
return false; } } return true; } } if ($object->xpdo) { $modx =& $object->xpdo; switch ($options[xPDOTransport::PACKAGE_ACTION]) { case xPDOTransport::ACTION_INSTALL: case xPDOTransport::ACTION_UPGRADE: $intersects = array(0 => array('pagetitle' => 'MyComponent', 'parent' => 'default', 'template' => 'MyComponentTemplate')); if (is_array($intersects)) { foreach ($intersects as $k => $fields) { /* make sure we have all fields */ if (!checkFields('pagetitle,parent,template', $fields)) { continue; } $resource = $modx->getObject('modResource', array('pagetitle' => $fields['pagetitle'])); if (!$resource) { continue; } if ($fields['template'] == 'default') { $resource->set('template', $modx->getOption('default_template')); } else { $templateObj = $modx->getObject('modTemplate', array('templatename' => $fields['template'])); if ($templateObj) { $resource->set('template', $templateObj->get('id')); } else { $modx->log(modX::LOG_LEVEL_ERROR, '[Resource Resolver] Could not find template: ' . $fields['template']); }
} $xml = simplexml_load_file($argv[1]); mysql_connect('localhost', 'root'); mysql_select_db($argv[2]); $f = fopen("sqlchanges.sql", 'w'); $tableRes = mysql_query('show tables;'); $tables = array(); while ($table = mysql_fetch_array($tableRes, MYSQL_NUM)) { $tables[$table[0]] = true; } foreach ($xml as $table) { foreach ($table as $structure) { $tableName = (string) $structure->attributes()->name; if (isset($tables[$tableName])) { echo "Table: " . $tableName . " found, checking fields...\n"; $retval = checkFields($tableName, $structure); if ($retval > 0) { echo $retval . " alter statements generated.\n"; } else { echo "Confirmed fields match.\n"; } } else { echo "Table: " . $tableName . " was not found, generating create sql\n"; $sql = "CREATE TABLE `{$structure->attributes()->name}` (\n"; $keys = array(); foreach ($structure as $objType => $field) { if ($objType == "field") { $sql .= "\t`{$field->attributes()->Field}` {$field->attributes()->Type} " . ($field->attributes()->Null == "NO" ? " NOT NULL " : " NULL ") . ",\n"; } elseif ($objType == 'key') { $xmlKeyName = (string) $field->attributes()->Key_name; if ($field->attributes()->Key_name == "PRIMARY") {
return false; } } return true; } } if ($object->xpdo) { $modx =& $object->xpdo; switch ($options[xPDOTransport::PACKAGE_ACTION]) { case xPDOTransport::ACTION_INSTALL: case xPDOTransport::ACTION_UPGRADE: $intersects = array(0 => array('widget' => 'Upgrade MODX', 'dashboard' => 1, 'rank' => 1)); if (is_array($intersects)) { foreach ($intersects as $k => $fields) { /* make sure we have all fields */ if (!checkFields('widget,dashboard', $fields)) { continue; } $widget = $modx->getObject('modDashboardWidget', array('name' => $fields['widget'])); $dashboard = $modx->getObject('modDashboard', (int) $fields['dashboard']); if (!$widget || !$dashboard) { if (!$widget) { $modx->log(xPDO::LOG_LEVEL_ERROR, 'Could not find Widget ' . $fields['widget']); } if (!$dashboard) { $modx->log(xPDO::LOG_LEVEL_ERROR, 'Could not find dashboard with ID ' . $fields['dashboard']); } continue; } $widgetPlacement = $modx->getObject('modDashboardWidgetPlacement', array('widget' => $widget->get('id'), 'dashboard' => (int) $fields['dashboard'])); if (!$widgetPlacement) {
</head> <body> <form method="POST"> <input name="login" id="login" type="text" placeholder="login"> <input name="pass" id="pass" type="password" placeholder="pass"> <input name="re_pass" id="re_pass" type="password" placeholder="re_pass"> <input name="email" id="email" type="email" placeholder="email"> <input type="submit" name="submit" > </form> <?php include './config/conf.php'; include './util/messager.php'; include './dao/person.php'; include './util/formsChecker.php'; if (isset($_POST["submit"])) { checkFields($_POST); } ?> <div class="info"> <span>Осуществить на стороне сервера валидацию полей формы (правила валидации берем из предыдущего домашнего задания). Проверить, есть ли пользователь с введенным логином и почтой в базе данных, если есть - вывести его имя.</span> </div> </body> </html>
return false; } } return true; } } if ($object->xpdo) { $modx =& $object->xpdo; switch ($options[xPDOTransport::PACKAGE_ACTION]) { case xPDOTransport::ACTION_INSTALL: case xPDOTransport::ACTION_UPGRADE: $intersects = '[[+intersects]]'; if (is_array($intersects)) { foreach ($intersects as $k => $fields) { /* make sure we have all fields */ if (!checkFields('category,parent', $fields)) { continue; } $categoryObj = $modx->getObject('modCategory', array('category' => $fields['category'])); if (!$categoryObj) { continue; } $parentObj = $modx->getObject('modCategory', array('category' => $fields['parent'])); if ($parentObj) { $categoryObj->set('parent', $parentObj->get('id')); } $categoryObj->save(); } } break; case xPDOTransport::ACTION_UNINSTALL:
return false; } } return true; } } if ($object->xpdo) { $modx =& $object->xpdo; switch ($options[xPDOTransport::PACKAGE_ACTION]) { case xPDOTransport::ACTION_INSTALL: case xPDOTransport::ACTION_UPGRADE: $intersects = '[[+intersects]]'; if (is_array($intersects)) { foreach ($intersects as $k => $fields) { /* make sure we have all fields */ if (!checkFields('tmplvarid,templateid', $fields)) { continue; } $tv = $modx->getObject('modTemplateVar', array('name' => $fields['tmplvarid'])); if ($fields['templateid'] == 'default') { $template = $modx->getObject('modTemplate', $modx->getOption('default_template')); } else { $template = $modx->getObject('modTemplate', array('templatename' => $fields['templateid'])); } if (!$tv || !$template) { $modx->log(xPDO::LOG_LEVEL_ERROR, 'Could not find Template and/or TV ' . $fields['templateid'] . ' - ' . $fields['tmplvarid']); continue; } $tvt = $modx->getObject('modTemplateVarTemplate', array('templateid' => $template->get('id'), 'tmplvarid' => $tv->get('id'))); if (!$tvt) { $tvt = $modx->newObject('modTemplateVarTemplate');
case xPDOTransport::ACTION_UPGRADE: foreach ($newEvents as $k => $fields) { $event = $modx->getObject('modEvent', array('name' => $fields['name'])); if (!$event) { $event = $modx->newObject('modEvent'); if ($event) { $event->fromArray($fields, "", true, true); $event->save(); } } } $intersects = array(0 => array('pluginid' => 'GeoTV', 'event' => 'OnTVInputRenderList', 'priority' => '0', 'propertyset' => '0'), 1 => array('pluginid' => 'GeoTV', 'event' => 'OnTVOutputRenderList', 'priority' => '0', 'propertyset' => '0'), 2 => array('pluginid' => 'GeoTV', 'event' => 'OnTVInputPropertiesList', 'priority' => '0', 'propertyset' => '0'), 3 => array('pluginid' => 'GeoTV', 'event' => 'OnTVOutputRenderPropertiesList', 'priority' => '0', 'propertyset' => '0'), 4 => array('pluginid' => 'GeoTV', 'event' => 'OnDocFormPrerender', 'priority' => '0', 'propertyset' => '0')); if (is_array($intersects)) { foreach ($intersects as $k => $fields) { /* make sure we have all fields */ if (!checkFields('pluginid,event,priority,propertyset', $fields)) { continue; } $event = $modx->getObject('modEvent', array('name' => $fields['event'])); $plugin = $modx->getObject('modPlugin', array('name' => $fields['pluginid'])); $propertySetObj = null; if (!empty($fields['propertyset'])) { $propertySetObj = $modx->getObject('modPropertySet', array('name' => $fields['propertyset'])); } if (!$plugin || !$event) { $modx->log(xPDO::LOG_LEVEL_ERROR, 'Could not find Plugin and/or Event ' . $fields['plugin'] . ' - ' . $fields['event']); continue; } $pluginEvent = $modx->getObject('modPluginEvent', array('pluginid' => $plugin->get('id'), 'event' => $fields['event'])); if (!$pluginEvent) { $pluginEvent = $modx->newObject('modPluginEvent');
return false; } } return true; } } if ($object->xpdo) { $modx =& $object->xpdo; switch ($options[xPDOTransport::PACKAGE_ACTION]) { case xPDOTransport::ACTION_INSTALL: case xPDOTransport::ACTION_UPGRADE: $intersects = '[[+intersects]]'; if (is_array($intersects)) { foreach ($intersects as $k => $fields) { /* make sure we have all fields */ if (!checkFields('element,element_class,property_set', $fields)) { continue; } $elementObj = $modx->getObject($fields['element_class'], array(getNameAlias($fields['element_class']) => $fields['element'])); $propertySetObj = $modx->getObject('modPropertySet', array('name' => $fields['property_set'])); if (!$elementObj || !$propertySetObj) { $modx->log(xPDO::LOG_LEVEL_ERROR, 'Could not find Element and/or Property Set ' . $fields['element'] . ' - ' . $fields['property_set']); continue; } $fields['element'] = $elementObj->get('id'); $fields['property_set'] = $propertySetObj->get('id'); $tvt = $modx->getObject('modElementPropertySet', $fields); if (!$tvt) { $tvt = $modx->newObject('modElementPropertySet'); } if ($tvt) {