Пример #1
0
    /**
     * Fetches the appropriate Userdata neede to Display all of them
     *
     * This function gets invoked by an Javascript-Script. It parses the data
     * and fetches userdata in one Query. It sends JSON-encoded data back.
     *
     * @uses  $_POST['pagenumber'] The pagenumber to be displayed
     * @uses  $_POST['usersPerPage'] How many Users are displayed per Page
     * @uses  $_POST['sortFor'] What column should be sorted
     * @uses  $_POST['filterForCol'] What Column should be filtered
     * @uses  $_POST['filterForVal'] The value to filter for
     */
    public function fetchUsersOrganized()
    {
        $pagenumber = $_POST['pagenumber'];
        $usersPerPage = $_POST['usersPerPage'];
        $sortFor = $_POST['sortFor'];
        $filterForVal = $_POST['filterForVal'];
        $toEscape = array(&$pagenumber, &$usersPerPage, &$sortFor, &$filterForVal);
        TableMng::sqlEscapeByArray($toEscape);
        $userToStart = ($pagenumber - 1) * $usersPerPage;
        if (empty($_POST['columnsToFetch'])) {
            $columnsToFetch = array();
        } else {
            $columnsToFetch = $_POST['columnsToFetch'];
            foreach ($columnsToFetch as &$col) {
                TableMng::sqlEscape($col);
            }
        }
        $filterForColumns = array();
        if (!empty($_POST['filterForColumns'])) {
            foreach ($_POST['filterForColumns'] as &$col) {
                TableMng::sqlEscape($col);
            }
            $filterForColumns = $_POST['filterForColumns'];
        }
        //When joining multiple tables, we have multiple IDs
        if ($filterForVal == 'ID') {
            $filterForVal = 'u.ID';
        }
        //When user didnt select anything to sort For, default to Id
        if (empty($sortFor)) {
            $sortFor = 'ID';
        }
        //Set the method of sorting
        $sortMethod = $_POST['sortMethod'] == 'ASC' ? 'ASC' : 'DESC';
        try {
            $queryCreator = new UserDisplayAllQueryCreator($this->_pdo, $filterForColumns, $sortFor, $sortMethod, $userToStart, $usersPerPage);
            $query = $queryCreator->createQuery($columnsToFetch, $sortFor, $filterForVal);
            $countQuery = $queryCreator->createCountOfQuery($columnsToFetch, $sortFor, $filterForVal);
            // var_dump($query);
            // die();
            //Fetch the Userdata
            TableMng::query('SET @activeSy :=
				(SELECT ID FROM SystemSchoolyears WHERE active = "1");');
            $data = TableMng::query($query);
            $usercount = TableMng::query($countQuery);
            // No division by zero, never show zero sites
            if ($usersPerPage != 0 && $usercount[0]['count'] > 0) {
                $pagecount = ceil((int) $usercount[0]['count'] / (int) $usersPerPage);
            } else {
                $pagecount = 1;
            }
            $data = $this->fetchedDataToReadable($data, $columnsToFetch);
        } catch (Exception $e) {
            $this->_logger->log('Error processing the data', 'Error', Null, json_encode(array('msg' => $e->getMessage())));
            die(json_encode(array('value' => 'error', 'message' => 'Ein Fehler ist bei der Datenverarbeitung ' . 'aufgetreten.')));
        }
        die(json_encode(array('value' => 'data', 'users' => $data, 'pagecount' => $pagecount)));
    }
Пример #2
0
 /**
  * Uploads the changes of the TimeModification-Strings to the Database
  */
 protected function submoduleChangeExecute()
 {
     TableMng::sqlEscapeByArray($_POST);
     if ($this->inputDataCheck($_POST)) {
         $this->changeDataToDb($_POST);
     } else {
         $this->_interface->dieError('Not enough Data given');
     }
     $this->_interface->dieMsg('Die Daten wurden erfolgreich verändert.');
 }