public function execute() {

       	$request = $this->getContext()->getRequest();

    	$postLoginUser = $request->getParameter('user');
    	$postLoginId = $postLoginUser['id'];

    	$id = $request->getParameter('id');

		$login = $this->getContext()->getUser()->getAttribute('Login');
    	$loginRole = $this->getLoginRole();

    	if ($loginRole == 'editor'){
    		if ($id != $login->id && $postLoginId != $login->id){

				$this->log("Unauthorized attempt edit login record. Login id: $id, user name: ". $login->name);
    					
    			$this->getContext()->getController()->forward('Default', "Secure");	
    		}
    	}

//    	$this->checkAdminAuth();

		if($request->getParameter('cancel')) {

			if ($loginRole == 'admin'){
				$this->getContext()->getController()->forward('Default', "ListLogin");
			} else {
				header("Location:Search?searchFor=Member");
			}

			return View::NONE;
		}
        
    	$form = new HTML_QuickForm("loginForm", 'post');

    	$loginDao = new BaseDao("Login");

		$affDao = new BaseDao("Affiliate"); 

    	if ($id){
    		$user = $loginDao->get($id);	

			$this->log("Editing login: "******" ,name: ".$user->name);
			$this->log("Editing login: "******" ,name: ".$user->name, true);

    		$affiliate = $affDao->getPattern();
    		$affiliate->editor = $user->id;
			$currentAffs = $affDao->search($affiliate);
			$affIds = $this->getListOfCertainFieldValues($currentAffs, 'id');

    		$form->setDefaults(array('user' => (array) $user, 
    								 "password2" => $user->password,
    								 "affiliates" => $affIds));
    	} else{
			$this->log("Creating new login.", true);

	    	$user = $loginDao->getPattern();
    	}

		$request->setAttribute('user', $user);

		$roleDao = new BaseDao("Role"); 
		$roles = $this->prepareDropdown($roleDao->search(), 'id', 'name');

		$affs = $this->prepareDropdown($affDao->searchWhereWithOrder($affDao->getPattern(), "1=1", 'name'), 'id', 'name');

		$form->addElement("text", "user[name]", "Name:", array('size' => 50, "maxlength" => 255));
		$form->addElement("text", "user[login]", "Login:"******"maxlength" => 255));
		$form->addElement("password", "user[password]", "Password:"******"maxlength" => 255));
		$form->addElement("password", "password2", "Repeat Password:"******"maxlength" => 255));
		$form->addElement('text', "user[email]", 'Email:', array('size' => 50, "maxlength" => 255));
		$form->addElement('select', "user[roleFid]", "User Role:", $roles);
		$form->addElement('select', "affiliates", "Affiliate:", $affs, array('multiple' => 'multiple', 'id' => "affDropdown") );
		$form->addElement('checkbox', "user[nationalOfficer]", "National Officer:", "", array());

		$element =& $form->getElement("affiliates");
		$element->setSize(5);
		if ($loginRole != 'admin') $element->freeze();

		$form->addElement('hidden', 'user[id]');
		$form->addElement("submit", null, "Save Changes");
		$form->addElement("submit", 'cancel', "Cancel");

		$form->addRule("user[name]", "Please enter your name.", 'required', null);
		$form->addRule("user[login]", "Login can't be blank.", 'required', null);
		$form->addRule("user[password]", "You haven't entered password.", 'required', null);
		$form->addRule("user[email]", "Please enter your email.", 'required', null);
		$form->addRule("user[email]", "Please enter valid email.", 'email', null);

		$form->addFormRule(array(&$this, "validatePassword"));
		$form->addFormRule(array(&$this, "checkEmail"));
		$form->addFormRule(array(&$this, "max5admins"));



		if (!$form->validate()) {

			$request->setAttribute("editLoginForm", $form->toHtml());

			return 'Form';
		}
		else{	
			$reqUser = $request->getParameter('user');

			$user->id = $reqUser['id'];
			$user->login = $reqUser['login'];
			$user->password = $reqUser['password'];
			$user->email = $reqUser['email'];
			$user->roleFid = $reqUser['roleFid'];
			$user->name = $reqUser['name'];

			if ($reqUser["nationalOfficer"]){
				$this->log("Assigng new national Officer: ".$user->login." ,name: ".$user->name, true);

				$user->nationalOfficer = 1;		
				$db = new PearDBStorage();
				$db->invoke("update logins set nationalOfficer=0 where nationalOfficer=1");
			}

			$loginDao->save($user);

			$affiliates = $reqUser = $request->getParameter("affiliates");
			$affText = "";
			if ($affiliates){
				foreach($affiliates as $affId){
					$affiliate = $affDao->get($affId);
					$affiliate->editor = $user->id;
					$affDao->save($affiliate);

					$affText .= $affiliate->name." ";
				}
			}

			if (!$user->id){

				$emailMessage = "Dear ".$user->name.":\n\n
				You have been assigned the role of Editor in the American Council of the Blind membership database for ".$affText.".\n
				Your User ID is ".$user->login." and your default password is ".$user->password.".  Please change this password immediately when you log into the database.\n\n
				Thank you for your work both in your affiliate and with the ACB management of the most precious resource we have:  Our members.\n\n
				Sincerely,\n\n
				The Database Management Team";

				mail($user->email, "ACB mail", $emailMessage);
			}

			if ($loginRole == 'admin'){
				$this->log("Saving login: "******" ,name: ".$user->name, true);

				$this->getContext()->getController()->forward('Default', "ListLogin");
			} else {
				$this->log("Saving login: "******" ,name: ".$user->name);

				header("Location:Search?searchFor=Member");
			}

			return View::NONE;
		}
    }
 * Different messages we put in the template
 */
$tpl->assign('msg', array("addL" => "?p=" . $p . "&o=a", "addT" => _("Add"), "delConfirm" => _("Do you confirm the deletion ?")));
/*
 * Toolbar select 
 */
?>
	<script type="text/javascript">
	function setO(_i) {
		document.forms['form'].elements['o'].value = _i;
	}
	</SCRIPT>
	<?php 
$attrs = array('onchange' => "javascript: " . "if (this.form.elements['o1'].selectedIndex == 1 && confirm('" . _("Do you confirm the duplication ?") . "')) {" . " \tsetO(this.form.elements['o1'].value); submit();} " . "else if (this.form.elements['o1'].selectedIndex == 2 && confirm('" . _("Do you confirm the deletion ?") . "')) {" . " \tsetO(this.form.elements['o1'].value); submit();} " . "else if (this.form.elements['o1'].selectedIndex == 3) {" . " \tsetO(this.form.elements['o1'].value); submit();} " . "");
$form->addElement('select', 'o1', NULL, array(NULL => _("More actions..."), "m" => _("Duplicate"), "d" => _("Delete")), $attrs);
$form->setDefaults(array('o1' => NULL));
$o1 = $form->getElement('o1');
$o1->setValue(NULL);
$attrs = array('onchange' => "javascript: " . "if (this.form.elements['o2'].selectedIndex == 1 && confirm('" . _("Do you confirm the duplication ?") . "')) {" . " \tsetO(this.form.elements['o2'].value); submit();} " . "else if (this.form.elements['o2'].selectedIndex == 2 && confirm('" . _("Do you confirm the deletion ?") . "')) {" . " \tsetO(this.form.elements['o2'].value); submit();} " . "else if (this.form.elements['o2'].selectedIndex == 3) {" . " \tsetO(this.form.elements['o2'].value); submit();} " . "");
$form->addElement('select', 'o2', NULL, array(NULL => _("More actions..."), "m" => _("Duplicate"), "d" => _("Delete")), $attrs);
$form->setDefaults(array('o2' => NULL));
$o2 = $form->getElement('o2');
$o2->setValue(NULL);
$tpl->assign('limit', $limit);
/*
 * Apply a template definition
 */
$renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl);
$form->accept($renderer);
$tpl->assign('form', $renderer->toArray());
$tpl->display("listCollectors.ihtml");
function admin_display($task)
{
    global $db, $cfg;
    if ($task == NULL) {
        $task = 'contests';
    }
    switch ($task) {
        case 'users':
            $table = new HTML_Table();
            $res =& db_query('users_list');
            $res->fetchInto($row);
            // add users table headers
            $headers = array_keys($row);
            array_push($headers, 'groups');
            array_push($headers, 'actions');
            $table->addRow($headers, null, 'TH');
            // add user records
            while ($row) {
                $res2 =& db_query('groups_by_user_id', $row['user_id']);
                // get list of gourps for this user
                $groups = '';
                $res2->fetchInto($row2);
                while ($row2) {
                    $groups .= $row2['name'];
                    if ($res2->fetchInto($row2)) {
                        $groups .= ', ';
                    }
                }
                $res2->free();
                array_push($row, $groups);
                // actions
                array_push($row, "<a href=\"index.php?view=admin&amp;task=edit_user&amp;id={$row['user_id']}\">edit</a>" . ", <a href=\"index.php?view=admin&amp;task=del_user&amp;id={$row['user_id']}\">delete</a>");
                $table->addRow(array_values($row));
                $res->fetchInto($row);
            }
            $res->free();
            $table->altRowAttributes(1, null, array("class" => "altrow"));
            echo '<div class="overflow">' . $table->toHtml() . '</div>';
            break;
        case 'del_user':
            db_query('del_user_by_id', $_GET['id']);
            db_query('del_user_perms_by_id', $_GET['id']);
            redirect('index.php?view=admin&task=users');
            break;
        case 'edit_user':
            // user id to edit given as arg
            $res =& db_query('groups_by_user_id', $_GET['id']);
            // get list of all groups for this user
            $user_groups = array();
            while ($res->fetchInto($row)) {
                array_push($user_groups, $row['group_id']);
            }
            $res->free();
            // get hanndle of user
            $res =& db_query('user_by_id', $_GET['id']);
            $res->fetchInto($row);
            $handle = $row['handle'];
            $res->free();
            $form = new HTML_QuickForm('userForm', 'post', 'index.php?view=admin&task=edit_user&id=' . $_GET['id']);
            $form->addElement('header', null, 'Groups for user ' . $handle . ' (id: ' . $_GET['id'] . ')');
            // get list of all available groups
            $res =& db_query('groups_list');
            // add checkbox for each group
            $groups = array();
            while ($res->fetchInto($row)) {
                $elem =& $form->addElement('checkbox', $row['group_id'], $row['name']);
                if (in_array($row['group_id'], $user_groups)) {
                    $elem->setChecked(true);
                }
                $groups[$row['group_id']] = $row['name'];
            }
            $res->free();
            $form->addElement('submit', 'submit', 'Apply Changes');
            if ($form->validate()) {
                $data = $form->getSubmitValues();
                foreach ($groups as $gid => $name) {
                    $elem =& $form->getElement($gid);
                    if ($data[$gid] == 1) {
                        auth_set_perm($_GET['id'], $gid);
                        $elem->setChecked(true);
                    } else {
                        auth_clear_perm($_GET['id'], $gid);
                        $elem->setChecked(false);
                    }
                }
            }
            $form->display();
            break;
        case 'groups':
            $table = new HTML_Table();
            $res =& db_query('groups_list');
            $res->fetchInto($row);
            // add groups table header
            $headers = array_keys($row);
            array_push($headers, 'views');
            array_push($headers, 'actions');
            $table->addRow($headers, null, 'TH');
            // add group records
            while ($row) {
                $res2 =& db_query('views_by_group_id', $row['group_id']);
                // get list of views allowed for this group
                $views = '';
                $res2->fetchInto($row2);
                while ($row2) {
                    $views .= $row2['view'];
                    if ($res2->fetchInto($row2)) {
                        $views .= ', ';
                    }
                }
                $res2->free();
                array_push($row, $views);
                array_push($row, "<a href=\"index.php?view=admin&amp;task=edit_group&amp;id={$row['group_id']}\">edit</a>" . ", <a href=\"index.php?view=admin&amp;task=del_group&amp;id={$row['group_id']}\">delete</a>");
                $table->addRow(array_values($row));
                $res->fetchInto($row);
            }
            $res->free();
            // decor
            $table->altRowAttributes(1, null, array("class" => "altrow"));
            echo '<div class="overflow">' . $table->toHtml() . '</div>';
            echo "<hr />";
            // form for adding a group
            $form = new HTML_QuickForm('addGroupForm', 'post', 'index.php?view=admin&task=groups');
            $form->addElement('header', null, 'Add a group');
            $form->addElement('text', 'name', 'Name: ');
            $form->addElement('submit', null, 'Submit');
            $form->applyFilter('name', 'trim');
            $form->addRule('name', 'Group name is required.', 'required', null, 'client');
            if ($form->validate()) {
                $res =& $db->autoExecute('groups', $form->getSubmitValues(), DB_AUTOQUERY_INSERT);
                if (PEAR::isError($res)) {
                    error($db->toString());
                }
                redirect('index.php?view=admin&task=groups');
            }
            $form->display();
            break;
        case 'del_group':
            db_query('del_group_by_id', $_GET['id']);
            redirect('index.php?view=admin&task=groups');
            break;
        case 'edit_group':
            // get list of views allowed for this group
            $group_views = array();
            $res =& db_query('views_by_group_id', $_GET['id']);
            while ($res->fetchInto($row)) {
                array_push($group_views, $row['view']);
            }
            $res->free();
            // get name of group
            $res =& db_query('group_by_id', $_GET['id']);
            $res->fetchInto($row);
            $name = $row['name'];
            $res->free();
            $form = new HTML_QuickForm('groupForm', 'post', 'index.php?view=admin&task=edit_group&id=' . $_GET['id']);
            $form->addElement('header', null, 'Views for group ' . $name . ' (id: ' . $_GET['id'] . ')');
            // get list of all available views
            $view_paths = glob($cfg['dir']['views'] . '/*.php');
            $views = array();
            // create the checkboxes, add each view to $views for later checking
            foreach ($view_paths as $path) {
                $tmp = explode('.', basename($path));
                $elem =& $form->addElement('checkbox', $tmp[0], $tmp[0]);
                if (in_array($tmp[0], $group_views)) {
                    $elem->setChecked(true);
                }
                array_push($views, $tmp[0]);
            }
            $form->addElement('submit', 'submit', 'Apply Changes');
            if ($form->validate()) {
                $data = $form->getSubmitValues();
                foreach ($views as $view) {
                    $elem =& $form->getElement($view);
                    if ($data[$view] == 1) {
                        auth_set_view($_GET['id'], $view);
                        $elem->setChecked(true);
                    } else {
                        auth_clear_view($_GET['id'], $view);
                        $elem->setChecked(false);
                    }
                }
            }
            $form->display();
            break;
        case 'views':
            $table = new HTML_Table();
            $table->addRow(array('name', 'path'), null, 'TH');
            // display list of views
            $view_paths = glob($cfg['dir']['views'] . '/*.php');
            foreach ($view_paths as $path) {
                $tmp = explode('.', basename($path));
                $table->addRow(array($tmp[0], $path));
            }
            $table->altRowAttributes(1, null, array("class" => "altrow"));
            echo '<div class="overflow">' . $table->toHtml() . '</div>';
            ?>
<p>To add a view, just drop a .php view-module file inside the views directory.
You can remove a view by deleting or renaming the corresponding file
inside the views directory.
</p> 
		<?php 
            break;
        case 'contests':
            $table = new HTML_Table();
            $res =& db_query('contests_list');
            $res->fetchInto($row);
            if ($row) {
                // add contests table headers
                $headers = array_keys($row);
                array_push($headers, 'actions');
                $table->addRow($headers, null, 'TH');
                // add contests table records
                while ($row) {
                    // Get the handle of the manager for displaying
                    $manager_name = '[none]';
                    $res2 =& $db->query($cfg['sql']['user_by_id'], $row['manager']);
                    if (!PEAR::isError($res2)) {
                        $res2->fetchInto($row2);
                        $manager_name = $row2['handle'];
                        $res2->free();
                    }
                    $row['manager'] = $manager_name;
                    // add edit,delete actions
                    $row['actions'] = "<a href=\"index.php?view=admin&amp;task=edit_contest&amp;id={$row['contest_id']}\">edit</a>, " . "<a href=\"index.php?view=admin&amp;task=del_contest&amp;id={$row['contest_id']}\">delete</a>";
                    $table->addRow(array_values($row));
                    $res->fetchInto($row);
                }
                $res->free();
                // decoration
                $table->altRowAttributes(1, null, array("class" => "altrow"));
                echo '<div class="overflow">' . $table->toHtml() . '</div>';
            } else {
                ?>
<p>No contests added yet.</p>			
			<?php 
            }
            echo "<hr />";
            // get list of all available managers
            $res =& db_query('users_by_group_name', 'Managers');
            while ($res->fetchInto($row)) {
                $managers[$row['user_id']] = $row['handle'];
            }
            // form for adding a contest
            $form = new HTML_QuickForm('contestAddForm', 'post', selflink());
            $form->addElement('header', null, 'Add a contest');
            $form->addElement('text', 'name', 'Name:');
            $form->addElement('text', 'description', 'Description:');
            $elem =& $form->addElement('text', 'team_size', 'Size of team:');
            $form->addElement('select', 'division', 'Division:', $cfg['tcl']['divisions']);
            $elem->setValue('1');
            $date = getdate();
            $form->addElement('date', 'show_time', 'Activation time:', array('format' => 'dMY H:i', 'minYear' => $date['year'], 'maxYear' => $date['year'] + 5));
            $form->addElement('date', 'begin_time', 'Begin time:', array('format' => 'dMY H:i', 'minYear' => $date['year'], 'maxYear' => $date['year'] + 5));
            $form->addElement('date', 'end_time', 'End time:', array('format' => 'dMY H:i', 'minYear' => $date['year'], 'maxYear' => $date['year'] + 5));
            $form->addElement('select', 'manager', 'Contest manager:', $managers);
            $form->addElement('submit', null, 'Submit');
            $form->applyFilter('name', 'trim');
            $form->applyFilter('description', 'trim');
            $form->applyFilter('team_size', 'trim');
            $form->addRule('name', 'Contest name is required.', 'required', null, 'client');
            $form->addRule('manager', 'Contest manager is required.', 'required', null, 'client');
            $form->addRule('team_size', 'Team size is required.', 'required', null, 'client');
            // validate or display form
            if ($form->validate()) {
                $data = $form->getSubmitValues();
                $data['show_time'] = form2sql_datetime($data['show_time']);
                $data['begin_time'] = form2sql_datetime($data['begin_time']);
                $data['end_time'] = form2sql_datetime($data['end_time']);
                $db->autoExecute('contests', $data, DB_AUTOQUERY_INSERT);
                if (PEAR::isError($res)) {
                    error($db->toString());
                }
                redirect('index.php?view=admin&task=contests');
            } else {
                $form->display();
            }
            break;
        case 'del_contest':
            $res =& db_query('del_contest_by_id', $_GET['id']);
            redirect('index.php?view=admin&task=contests');
            break;
        case 'edit_contest':
            // contest to edit given as arg
            $res =& db_query('contest_by_id', $_GET['id']);
            $res->fetchInto($row);
            $res->free();
            // get list of all available managers
            $res =& db_query('users_by_group_name', 'Managers');
            while ($res->fetchInto($row2)) {
                $managers[$row2['user_id']] = $row2['handle'];
            }
            // form for editing the contest
            $form = new HTML_QuickForm('contestEditForm', 'post', selflink());
            $form->addElement('header', null, "Edit contest {$row['name']} (id: {$row['contest_id']})");
            $form->addElement('text', 'name', 'Name:');
            $form->addElement('text', 'description', 'Description:');
            $elem =& $form->addElement('text', 'team_size', 'Size of team:');
            $elem->setValue('1');
            $form->addElement('select', 'division', 'Division:', $cfg['tcl']['divisions']);
            $date = getdate();
            $form->addElement('date', 'show_time', 'Activation time:', array('format' => 'dMY H:i', 'minYear' => $date['year'], 'maxYear' => $date['year'] + 5));
            $form->addElement('date', 'begin_time', 'Begin time:', array('format' => 'dMY H:i', 'minYear' => $date['year'], 'maxYear' => $date['year'] + 5));
            $form->addElement('date', 'end_time', 'End time:', array('format' => 'dMY H:i', 'minYear' => $date['year'], 'maxYear' => $date['year'] + 5));
            $form->addElement('select', 'manager', 'Contest manager:', $managers);
            $form->addElement('text', 'rules', 'Rules URL:');
            $form->addElement('submit', null, 'Submit');
            // convert date format and dtore default values
            $row['show_time'] = sql2form_datetime($row['show_time']);
            $row['begin_time'] = sql2form_datetime($row['begin_time']);
            $row['end_time'] = sql2form_datetime($row['end_time']);
            $form->setDefaults($row);
            $form->applyFilter('name', 'trim');
            $form->applyFilter('description', 'trim');
            $form->applyFilter('team_size', 'trim');
            $form->addRule('name', 'Contest name is required.', 'required', null, 'client');
            $form->addRule('manager', 'Contest manager is required.', 'required', null, 'client');
            $form->addRule('team_size', 'Team size is required.', 'required', null, 'client');
            // validate or display form
            if ($form->validate()) {
                $data = $form->getSubmitValues();
                $data['show_time'] = form2sql_datetime($data['show_time']);
                $data['begin_time'] = form2sql_datetime($data['begin_time']);
                $data['end_time'] = form2sql_datetime($data['end_time']);
                $db->autoExecute('contests', $data, DB_AUTOQUERY_UPDATE, 'contest_id=' . $_GET['id']);
                if (PEAR::isError($res)) {
                    error($db->toString());
                }
                redirect('index.php?view=admin&task=contests');
            } else {
                $form->display();
            }
            break;
        case 'shell':
            $form = new HTML_QuickForm('shellForm', 'post', selflink());
            $field =& $form->addElement('text', 'command', 'Command:');
            $field->setSize(100);
            $ifield =& $form->addElement('textarea', 'input', 'Standard Input:');
            $ifield->setRows(10);
            $ifield->SetCols(80);
            $form->addElement('submit', null, 'Submit');
            $form->display();
            if ($form->validate()) {
                // Write std input file
                $iname = tempnam("/tmp", "in");
                $ifile = fopen($iname, 'w');
                fwrite($ifile, $form->getSubmitValue('input'));
                fclose($ifile);
                $cmd = $form->getSubmitValue('command');
                echo "<pre class=\"shell_output\">";
                echo "<b>\$ " . html_escape($cmd) . "</b>\n";
                exec("{$cmd} 2>&1 < {$iname}", $out, $ret);
                foreach ($out as $line) {
                    echo html_escape($line) . "\n";
                }
                echo "</pre>\n";
                echo "<p>Command returned: {$ret}</p>\n";
            }
            break;
        case 'uploader':
            // Get list of directories to which files can be uploaded
            $dirs = subdir_list('.');
            array_unshift($dirs, './');
            $form = new HTML_QuickForm('uploaderForm', 'post', selflink());
            $form->addElement('header', null, 'Upload a File:');
            $file =& $form->addElement('file', 'file', 'File:');
            $form->addElement('select', 'dir', 'Destination:', $dirs);
            $form->addElement('submit', 'upload', 'Upload');
            $form->addRule('file', 'Please select file to upload.', 'required', null, 'client');
            $form->setMaxFileSize(10485760);
            // try 10 MB max file size
            if ($form->validate()) {
                if ($file->isUploadedFile()) {
                    $dir = $dirs[$form->getSubmitValue('dir')];
                    if ($file->moveUploadedFile($dir)) {
                        echo "<p>File uploaded successfully to {$dir}.</p>";
                    } else {
                        echo "<p>Failed to save uploaded file to {$dir} (insufficient permissions?).</p>";
                    }
                } else {
                    echo "<p>File upload did not finish successfully</p>";
                }
            }
            $form->display();
            echo "<p><b>Note:</b> Any previous file with the same name will be replaced.</p>";
            echo "<hr />";
            $form = new HTML_QuickForm('mkdirForm', 'post', selflink());
            $form->addElement('header', null, 'Create a Directory:');
            $form->addElement('text', 'name', 'Name:');
            $form->addElement('select', 'dir', 'Destination:', $dirs);
            $form->addElement('submit', 'mkdir', 'Mkdir');
            $form->addRule('name', 'Please enter directory name.', 'required', null, 'client');
            if ($form->validate()) {
                $path = $dirs[$form->getSubmitValue('dir')] . '/' . $form->getSubmitValue('name');
                if (file_exists($path)) {
                    echo "<p><b>Warning:</b> File or directory {$path} already exists.</p>";
                } else {
                    if (mkdir($path)) {
                        echo "<p>Directory {$path} created.</p>";
                    } else {
                        echo "<p>Failed to create directory {$path}. Make sure parent directory permissions allow it.</p>";
                    }
                }
            }
            $form->display();
            break;
        case 'phpinfo':
            phpinfo();
            break;
    }
}
Exemple #4
0
require_once 'HTML/QuickForm.php';
require_once 'HTML/QuickForm/livesearch_select.php';
require_once 'myfunction.php';
// Instantiate the HTML_QuickForm object
$form = new HTML_QuickForm('firstForm');
// Add some elements to the form
$form->addElement('header', null, 'QuickForm example');
$form->addElement('livesearch_select', 'Nome', 'Example: Live Select, <br>select a name and return an ID <br>(useful for dropdown lists)', array('elementId' => 'search', 'callback' => array('Test', 'getTestName'), 'style' => '', 'divstyle' => '', 'ulstyle' => '', 'listyle' => '', 'searchZeroLength' => 1, 'buffer' => 350, 'printStyle' => 1, 'autoComplete' => 1, 'autoserverPath' => ''), array('size' => '50'));
$form->addElement('livesearch_select', 'Nome2', 'Example2: Live Select, <br>select a name and return an ID <br>(useful for dropdown lists)', array('elementId' => 'search2', 'callback' => array('Test', 'getTestName2')), 'size=30');
$form->addElement('text', 'required_field', '[errorTest]Some data:');
$form->addElement('submit', null, 'View', array('id' => 'submit'));
$form->addRule('required_field', 'Data required', 'required', null, 'server');
$form->addRule('Nome', 'Data required', 'required', null, 'server');
//example set default value only if form is not submitted
if (!isset($_POST['Nome2'])) {
    $el = $form->getElement('Nome2');
    $el->setValue(2);
}
if ($form->validate()) {
    echo "<pre>";
    print_r($_POST);
    echo "</pre>";
    $form->freeze();
}
// Output the form
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
  <title>Livesearch QuickForm Test</title>
 public function getModule()
 {
     $currentLesson = $this->getCurrentLesson();
     $smarty = $this->getSmartyVar();
     $smarty->assign("T_LESSON_ID", $currentLesson->lesson['id']);
     if (isset($_GET['delete_link']) && eF_checkParameter($_GET['delete_link'], 'id')) {
         eF_deleteTableData("module_links", "id=" . $_GET['delete_link']);
         $this->setMessageVar(_LINKS_SUCCESFULLYDELETEDLINK, 'success');
         eF_redirect("" . $this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type={$message_type}");
     } else {
         if (isset($_GET['add_link']) || isset($_GET['edit_link']) && eF_checkParameter($_GET['edit_link'], 'id')) {
             $form = new HTML_QuickForm("link_entry_form", "POST", $_SERVER['REQUEST_URI'], "");
             $form->registerRule('checkParameter', 'callback', 'eF_checkParameter');
             //Register this rule for checking user input with our function, eF_checkParameter
             $form->addElement('text', 'display', null);
             $form->addElement('text', 'link', null);
             $form->addElement('textarea', 'description', null);
             $form->addElement('submit', 'submit_link', _SUBMIT, 'class = "flatButton"');
             $element =& $form->getElement('display');
             $element->setSize(50);
             $element =& $form->getElement('link');
             $element->setSize(50);
             $element =& $form->getElement('description');
             $element->setCols(50);
             if (isset($_GET['edit_link'])) {
                 $link_entry = eF_getTableData("module_links", "*", "id=" . $_GET['edit_link']);
                 $form->setDefaults(array('display' => $link_entry[0]['display'], 'link' => $link_entry[0]['link'], 'description' => $link_entry[0]['description']));
             } else {
                 $form->setDefaults(array('link' => "http://"));
             }
             if ($form->isSubmitted() && $form->validate()) {
                 $fields = array('lessons_ID' => $_SESSION['s_lessons_ID'], 'display' => $form->exportValue('display'), 'link' => $form->exportValue('link'), 'description' => $form->exportValue('description'));
                 if (isset($_GET['edit_link'])) {
                     if (eF_updateTableData("module_links", $fields, "id=" . $_GET['edit_link'])) {
                         $message = _LINKS_SUCCESFULLYUPDATEDLINKENTRY;
                         $message_type = 'success';
                         eF_redirect("" . $_SERVER['PHP_SELF'] . "?ctg=module&op=module_links&message=" . urlencode($message) . "&message_type={$message_type}");
                     } else {
                         $message = _LINKS_PROBLEMUPDATINGLINKENTRY;
                         $message_type = 'failure';
                         eF_redirect("" . $_SERVER['PHP_SELF'] . "?ctg=module&op=module_links&message=" . urlencode($message) . "&message_type={$message_type}");
                     }
                 } else {
                     if (eF_insertTableData("module_links", $fields)) {
                         $message = _LINKS_SUCCESFULLYINSERTEDLINKENTRY;
                         $message_type = 'success';
                         eF_redirect("" . $_SERVER['PHP_SELF'] . "?ctg=module&op=module_links&message=" . urlencode($message) . "&message_type={$message_type}");
                     } else {
                         $message = _LINKS_PROBLEMINSERTINGLINKENTRY;
                         $message_type = 'failure';
                         eF_redirect("" . $_SERVER['PHP_SELF'] . "?ctg=module&op=module_links&message=" . urlencode($message) . "&message_type={$message_type}");
                     }
                 }
             }
             $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
             $form->accept($renderer);
             $smarty->assign('T_LINKS_FORM', $renderer->toArray());
         } else {
             $links = eF_getTableDataFlat("module_links", "*", "lessons_ID = " . $_SESSION['s_lessons_ID']);
             $smarty->assign("T_LINKS", $links);
         }
     }
     return true;
 }
Exemple #6
0
                    fclose($stream);
                }
                break;
                break;
            case 'courses':
                $token = $values['token'];
                if ($stream = fopen(G_SERVERNAME . 'api.php?action=courses&token=' . $token, 'r')) {
                    $output = stream_get_contents($stream);
                    fclose($stream);
                }
                break;
                break;
            case 'logout':
                $token = $values['token'];
                if ($stream = fopen(G_SERVERNAME . 'api.php?action=logout&token=' . $token, 'r')) {
                    $output = stream_get_contents($stream);
                    fclose($stream);
                }
                break;
        }
    }
}
$form->setDefaults(array('action' => $action_id));
$element =& $form->getElement('output');
$element->setValue($output);
$renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
$form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
$form->setRequiredNote(_REQUIREDNOTE);
$form->accept($renderer);
$smarty->assign('T_ACTION_FORM', $renderer->toArray());
$smarty->display('apidemo.tpl');
Exemple #7
0
 private function _populateHierarchy($id, $hierarchy_id)
 {
     $element =& $this->_form->getElement($id);
     $hierarchy =& TIP_Type::getInstance($hierarchy_id);
     if ($element->isFrozen()) {
         // No need to execute a complete query: get only the selected row(s)
         $selected = $element->getSelected();
         $items = $hierarchy->toRow($selected);
     } else {
         // Populate the option list, prepending an empty option
         $items = array(' ' => '&#160;');
         is_null($rows =& $hierarchy->toRows()) || ($items += $rows);
     }
     $element->loadArray($items);
 }
Exemple #8
0
 $create_db_warn_msg = __('WARNING: Make sure you have CREATE access level to do this!');
 $form->addElement('select', 'newdb', __('Create new database'), array(0 => __('No'), 1 => __('Yes')), array('onChange' => 'if(this.value==1) alert("' . $create_db_warn_msg . '","warning");'));
 $form->addRule('newdb', __('Field required'), 'required');
 $form->addElement('header', null, __('Other settings'));
 $form->addElement('select', 'direction', __('Text direction'), array(0 => __('Left to Right'), 1 => __('Right to Left')));
 $form->addElement('submit', 'submit', __('Next'));
 $form->setDefaults(array('engine' => 'mysqlt', 'db' => 'epesi', 'host' => 'localhost'));
 $form->setRequiredNote('<span class="required_note_star">*</span> <span class="required_note">' . __('denotes required field') . '</span>');
 if (file_exists($fast_install_filename)) {
     include $fast_install_filename;
     if (isset($CONFIG) && is_array($CONFIG)) {
         $txt = __('Some fields were filled to make installation easier.');
         print '<div style="text-align:center"><p style="width: 250px;margin-left: auto;margin-right: auto;">' . $txt . '</p></div>';
         foreach ($CONFIG as $key => $value) {
             $form->setDefaults(array($key => $value));
             $form->getElement($key)->freeze();
         }
     }
 }
 $required_note_text = __('denotes required field');
 $form->setRequiredNote('<span class="required_note_star">*</span> <span class="required_note">' . $required_note_text . '</span>');
 $form->addElement('html', '<tr><td colspan=2><br /><b>' . __('Any existing tables will be dropped!') . '</b><br />' . __('The database will be populated with data.') . '<br />' . __('This operation can take several minutes.') . '</td></tr>');
 if ($form->validate()) {
     $engine = $form->exportValue('engine');
     $direction = $form->exportValue('direction');
     $other = array('direction' => $direction);
     $host = $form->exportValue('host');
     $port = $form->exportValue('port');
     $user = $form->exportValue('user');
     $pass = $form->exportValue('password');
     $dbname = $form->exportValue('db');
        $subC = $form->addElement('submit', 'submitC', _("Save"));
        $res = $form->addElement('reset', 'reset', _("Reset"));
        $form->setDefaults($cfg_poller);
    } else {
        if ($o == "a") {
            /*
             * Add a Poller information
             */
            $subA = $form->addElement('submit', 'submitA', _("Save"));
            $res = $form->addElement('reset', 'reset', _("Reset"));
        }
    }
}
$valid = false;
if ($form->validate()) {
    $pollerObj = $form->getElement('id');
    if ($form->getSubmitValue("submitA")) {
        insertPollerInDB();
    } else {
        if ($form->getSubmitValue("submitC")) {
            updatePollerInDB($id);
        }
    }
    $o = NULL;
    $valid = true;
}
if ($valid) {
    require_once $path . "listCollectors.php";
} else {
    /*
     * Apply a template definition
 public function getModule()
 {
     $currentLesson = $this->getCurrentLesson();
     $smarty = $this->getSmartyVar();
     $smarty->assign("T_LESSON_ID", $currentLesson->lesson['id']);
     if (isset($_GET['delete_quote']) && eF_checkParameter($_GET['delete_quote'], 'id')) {
         eF_deleteTableData("module_quote", "id=" . $_GET['delete_quote']);
         $this->setMessageVar(_QUOTE_SUCCESFULLYDELETEDQUOTE, 'success');
         eF_redirect("" . $this->moduleBaseUrl . "&message={$message}&message_type={$message_type}");
     } else {
         if (isset($_GET['add_quote']) || isset($_GET['edit_quote']) && eF_checkParameter($_GET['edit_quote'], 'id')) {
             $form = new HTML_QuickForm("quote_entry_form", "POST", $_SERVER['REQUEST_URI'], "");
             $form->registerRule('checkParameter', 'callback', 'eF_checkParameter');
             //Register this rule for checking user input with our function, eF_checkParameter
             $form->addElement('textarea', 'quote', null);
             $form->addElement('submit', 'submit_quote', _SUBMIT, 'class = "flatButton"');
             $element =& $form->getElement('quote');
             $element->setCols(100);
             if (isset($_GET['edit_quote'])) {
                 $quote_entry = eF_getTableData("module_quote", "*", "id=" . $_GET['edit_quote']);
                 $form->setDefaults(array('quote' => $quote_entry[0]['quote']));
             }
             if ($form->isSubmitted() && $form->validate()) {
                 $fields = array('lessons_ID' => $_SESSION['s_lessons_ID'], 'quote' => $form->exportValue('quote'));
                 if (isset($_GET['edit_quote'])) {
                     if (eF_updateTableData("module_quote", $fields, "id=" . $_GET['edit_quote'])) {
                         $message = _QUOTE_SUCCESFULLYUPDATEDQUOTEENTRY;
                         $message_type = 'success';
                         eF_redirect("" . $_SERVER['PHP_SELF'] . "?ctg=module&op=module_quote&message={$message}&message_type={$message_type}");
                     } else {
                         $message = _QUOTE_PROBLEMUPDATINGQUOTEENTRY;
                         $message_type = 'failure';
                         eF_redirect("" . $_SERVER['PHP_SELF'] . "?ctg=module&op=module_quote&message={$message}&message_type={$message_type}");
                     }
                 } else {
                     if (eF_insertTableData("module_quote", $fields)) {
                         $message = _QUOTE_SUCCESFULLYINSERTEDQUOTEENTRY;
                         $message_type = 'success';
                         eF_redirect("" . $_SERVER['PHP_SELF'] . "?ctg=module&op=module_quote&message={$message}&message_type={$message_type}");
                     } else {
                         $message = _QUOTE_PROBLEMINSERTINGQUOTEENTRY;
                         $message_type = 'failure';
                         eF_redirect("" . $_SERVER['PHP_SELF'] . "?ctg=module&op=module_quote&message={$message}&message_type={$message_type}");
                     }
                 }
             }
             $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
             $form->accept($renderer);
             $smarty->assign('T_QUOTE_FORM', $renderer->toArray());
         } else {
             $currentUser = $this->getCurrentUser();
             if ($currentUser->getType() == "professor") {
                 $quotes = eF_getTableDataFlat("module_quote", "*", "lessons_ID = " . $_SESSION['s_lessons_ID']);
                 $smarty->assign("T_QUOTES", $quotes);
             } else {
                 $quotes = eF_getTableDataFlat("module_quote", "*", "lessons_ID = " . $_SESSION['s_lessons_ID']);
                 $id = rand(0, sizeof($quotes) - 1);
                 $smarty->assign("T_QUOTE", $quotes['quote'][$id]);
             }
         }
     }
     return true;
 }
Exemple #11
0
 /**
  * 
  * @param type $elem
  * @return type
  */
 public function getElement($elem)
 {
     return $this->formProcessor->getElement($elem);
 }
    $form->freeze();
} else {
    if ($o == "c") {
        $subC =& $form->addElement('submit', 'submitC', _("Save"));
        $res =& $form->addElement('reset', 'reset', _("Reset"));
        $form->setDefaults($report);
    } else {
        if ($o == "a") {
            $subA =& $form->addElement('submit', 'submitA', _("Save"));
            $res =& $form->addElement('reset', 'reset', _("Reset"));
        }
    }
}
$valid = false;
if ($form->validate()) {
    $reportObj =& $form->getElement('report_id');
    if ($form->getSubmitValue("submitA")) {
        $reportObj->setValue(insertReportInDB());
    } else {
        if ($form->getSubmitValue("submitC")) {
            updateReportInDB($reportObj->getValue());
        }
    }
    $o = NULL;
    $form->addElement("button", "change", _("Modify"), array("onClick" => "javascript:window.location.href='?p=" . $p . "&o=c&report_id=" . $reportObj->getValue() . "'"));
    $form->freeze();
    $valid = true;
}
$action =& $form->getSubmitValue("action");
if ($valid && $action["action"]["action"]) {
    require_once $path . "listReport.php";