Ejemplo n.º 1
0
     $monitor = dbFetchOne("select * from Monitors where Id = ?", NULL, array($mid));
     if (ZM_OPT_X10) {
         $x10Monitor = dbFetchOne("select * from TriggersX10 where MonitorId=?", NULL, array($mid));
         if (!$x10Monitor) {
             $x10Monitor = array();
         }
     }
 } else {
     $monitor = array();
     if (ZM_OPT_X10) {
         $x10Monitor = array();
     }
 }
 // Define a field type for anything that's not simple text equivalent
 $types = array('Triggers' => 'set', 'Controllable' => 'toggle', 'TrackMotion' => 'toggle', 'Enabled' => 'toggle', 'DoNativeMotDet' => 'toggle');
 $columns = getTableColumns('Monitors');
 $changes = getFormChanges($monitor, $_REQUEST['newMonitor'], $types, $columns);
 if (count($changes)) {
     if (!empty($_REQUEST['mid'])) {
         $mid = validInt($_REQUEST['mid']);
         dbQuery("update Monitors set " . implode(", ", $changes) . " where Id =?", array($mid));
         if (isset($changes['Name'])) {
             $saferOldName = basename($monitor['Name']);
             $saferNewName = basename($_REQUEST['newMonitor']['Name']);
             rename(ZM_DIR_EVENTS . "/" . $saferOldName, ZM_DIR_EVENTS . "/" . $saferNewName);
         }
         if (isset($changes['Width']) || isset($changes['Height'])) {
             $newW = $_REQUEST['newMonitor']['Width'];
             $newH = $_REQUEST['newMonitor']['Height'];
             $newA = $newW * $newH;
             $oldW = $monitor['Width'];
Ejemplo n.º 2
0
function updateDatasetRow($params)
{
    $numParamsToUpdate = 0;
    // counts num of params to update.
    $sendParams = array();
    // make sure we have a content id and tablename
    if (isset($params['countryid']) && isset($params['tablename'])) {
        // gets array of fields name for 'tablename'
        $columnsArray = getTableColumns($params['tablename']);
        $sql = "UPDATE `" . $params['tablename'] . "` SET ";
        foreach ($params as $key => $value) {
            if ($key != 'action' && $key != 'countryid' && $key != 'tablename' && $key != 'tags' && $key != 'verbosity') {
                $numParamsToUpdate++;
                if (in_array($key, $columnsArray)) {
                    $sql .= "`" . $key . "` = :" . $key . ", ";
                    $sendParams[$key] = processText($value);
                } else {
                    die("Unknown field name '{$key}'.");
                }
            }
        }
        if ($numParamsToUpdate == 0) {
            //no other name/value pairs provided
            die("No name/value pairs provided to update.");
        } else {
            // remove last comma and space!
            $sql = substr($sql, 0, strlen($sql) - 2);
            $sql .= " WHERE countryid = :countryid";
            $sendParams['countryid'] = $params['countryid'];
        }
    } else {
        die("No id or tablename provided.");
    }
    if ($numParamsToUpdate > 0) {
        //echo $sql;
        //print_r($sendParams);
        if ($result = queryDatabase($sql, $sendParams)) {
            sendSuccess();
        }
    }
}
Ejemplo n.º 3
0
    /**
     * Creates an input form from the object columns
     * $which is an array that tells what columns to show
     * $action sets the action for the form
     * $hidden is an array that can be used to hide columns in the form (true), omit the column from the form (false)
     * or pass some hidden values into the form (non-boolean)
     */
    function inputForm($which = NULL, $action = NULL, $hidden = NULL)
    {
        $actionString = $action ? "action=\"{$action}\"" : "";
        $classname = get_class($this);
        $primary = $this->getPrimary();
        $which = $which ? $which : getTableColumns($this->getTableDefs());
        $attribs = $this->getAttribs();
        echo <<<FORMOPEN
<form id="{$classname}{$primary}" class="{$classname}" {$actionString} method="POST">

FORMOPEN;
        foreach ($which as $field) {
            if (!isset($hidden[$field])) {
                $this->inputField($field);
            }
        }
        if (is_array($hidden)) {
            foreach ($hidden as $key => $value) {
                if ($value === true) {
                    $attrib = $attribs[$key];
                    echo <<<HIDDENVALUE
\t<input type="hidden" name="{$key}" value="{$attrib}" />

HIDDENVALUE;
                } else {
                    if ($value !== false) {
                        echo <<<HIDDENVALUE
\t<input type="hidden" name="{$key}" value="{$value}" />

HIDDENVALUE;
                    } else {
                        if ($value === false) {
                            //Do nothing, omit this field
                        }
                    }
                }
            }
        }
        echo <<<FORMCLOSE
\t<input type="submit" name="submit" value="Go"/>
</form>

FORMCLOSE;
    }
Ejemplo n.º 4
0
function getMedia($params)
{
    /*
    		-- VALID PARAMS --
    		-- ALL ARE OPTIONAL --
    mediaid (int) - specifies a specific media id to return (can be comma-delimited)
    		contentid (int) - specifies a specific content id to return media results for (can be comma-delimited)
    		include_unused (1,0) - include media that is not tied to content - defaults to 0 (NO)
    		has_tag - comma-delimited list of tags to search for.
    		search_caption - search words to search for in description (comma-delimited).
    		search_credits - words to search for in the custom fields (comma-delimited).
    		orderby - field name to order results by, should be expressed as table.field (e.g. content.migtitle). Can also be comma-delimited list.
    		mimetype
    */
    global $mediaVerbosity;
    $columnsArray = getTableColumns('media');
    // gets array of field names for table 'media'
    $validParams = array("action", "mediaid", "contentid", "include_unused", "has_tag", "search_caption", "search_credits", "orderby", "name", "include_thumb", "verbosity");
    $sendParams = array();
    $i = 0;
    // SELECT fields according to verbosity
    if (!isset($params['verbosity'])) {
        // set default verbosity
        $params['verbosity'] = 0;
    }
    // BUILD SELECT STATEMENT FROM INFO IN VERBOSITY ARRAY!
    $sql = "SELECT ";
    if (@is_array($mediaVerbosity[$params['verbosity']])) {
        foreach ($mediaVerbosity[$params['verbosity']] as $field) {
            $sql .= $field . ",";
        }
    } else {
        die("Invalid verbosity level.");
    }
    $sql = substr($sql, 0, strlen($sql) - 1);
    $sql .= " FROM media\n\t\t\t  LEFT JOIN media_terms ON media_terms.mediaid = media.id\n\t\t\t  LEFT JOIN term_taxonomy ON term_taxonomy.id = media_terms.termid\n\t\t\t  LEFT JOIN terms ON term_taxonomy.termid = terms.id\n\t\t\t  LEFT JOIN content_media AS content_media ON  content_media.mediaid = media.id\n\t\t\t  LEFT JOIN content ON (content.id = content_media.contentid AND content.deleted='0') ";
    $sql .= " LEFT JOIN mimetypes ON (media.mimetypeid = mimetypes.id)";
    // WHERE CLAUSE INFO
    $sql .= " WHERE media.id <> 0 ";
    if (isset($params['mediaid'])) {
        // return a specific media id, or a list thereof
        $sql .= " AND media.id IN ( ";
        // $params['mediaid'] comma-delimited
        $manyvalues = explode(",", $params['mediaid']);
        foreach ($manyvalues as $value) {
            $sql .= " :singlevalue" . $value . ", ";
            $sendParams['singlevalue' . $value] = $value;
        }
        $sql = substr($sql, 0, strlen($sql) - 2);
        //remove last comma and space
        $sql .= " )";
    }
    if (isset($params['contentid'])) {
        // return media for a specific content id, or a list thereof
        $sql .= " AND content_media.contentid IN ( ";
        // $params['contentid'] comma-delimited
        $manyvalues = explode(",", $params['contentid']);
        foreach ($manyvalues as $value) {
            $sql .= " :singlevalue" . $value . ", ";
            $sendParams['singlevalue' . $value] = $value;
        }
        $sql = substr($sql, 0, strlen($sql) - 2);
        //remove last comma and space
        $sql .= " )";
    }
    if (!isset($params['include_unused']) || $params['include_unused'] == 0) {
        // return media for a specific content id, or a list thereof
        $sql .= " AND content_media.id IS NOT NULL";
    }
    if (isset($params['has_tag'])) {
        // search for tags
        $arrTags = explode(",", $params['has_tag']);
        if (is_array($arrTags)) {
            $sql .= " AND ( ";
            foreach ($arrTags as $term) {
                $i++;
                $sql .= " terms.name LIKE :term" . $i . " OR";
                $sendParams['term' . $i] = "%" . $term . "%";
            }
            $sql = substr($sql, 0, strlen($sql) - 2);
            $sql .= " ) ";
        } else {
            $sql .= " AND terms.name LIKE :has_tag ";
            $sendParams['has_tag'] = "%" . $params['has_tag'] . "%";
        }
    }
    if (isset($params['search_caption'])) {
        // search caption
        $arrSearchTerms = explode(",", $params['search_caption']);
        if (is_array($arrSearchTerms)) {
            $sql .= " AND ( ";
            foreach ($arrSearchTerms as $term) {
                $i++;
                $sql .= " media.caption LIKE :term" . $i . " OR";
                $sendParams['term' . $i] = "%" . $term . "%";
            }
            // remove last "OR"
            $sql = substr($sql, 0, strlen($sql) - 2);
            $sql .= " ) ";
        }
    }
    if (isset($params['search_credits'])) {
        // search credits
        $arrSearchTerms = explode(",", $params['search_credits']);
        if (is_array($arrSearchTerms)) {
            $sql .= " AND ( ";
            foreach ($arrSearchTerms as $term) {
                $i++;
                $sql .= " media.credits LIKE :term" . $i . " OR";
                $sendParams['term' . $i] = "%" . $term . "%";
            }
            // remove last "OR"
            $sql = substr($sql, 0, strlen($sql) - 2);
            $sql .= " ) ";
        }
    }
    // NOW, LETS GET ANY EXTRA PARAMS AND APPLY THOSE TO THE WHERE CLAUSE!
    foreach ($params as $key => $value) {
        if (!in_array($key, $validParams)) {
            if (in_array($key, $columnsArray)) {
                $sql .= " AND " . $key . " = :" . $key;
                $sendParams[$key] = $value;
            } else {
                die("Unknown field name '{$key}'.");
            }
        }
    }
    if (isset($params['include_thumb'])) {
        if ($params['include_thumb'] == '0') {
            $sql .= " AND content_media.usage_type != 'list_thumbnail' AND content_media.usage_type != 'main_thumbnail' ";
        }
    }
    $sql .= " GROUP BY media.id";
    // ORDER BY
    if (isset($params['orderby'])) {
        $sql .= " ORDER BY " . $params['orderby'];
    } else {
        if (isset($params['contentid'])) {
            $sql .= " ORDER BY content_media.displayorder ASC";
        } else {
            $sql .= " ORDER BY media.id ASC";
        }
    }
    //	print_r($sendParams);
    //print_r($sql);
    //print_r($sql);
    // get the results
    $result = queryDatabase($sql, $sendParams);
    // return the results
    return $result;
}
 public static function getReports($report_id = null)
 {
     global $Proj, $lang, $double_data_entry, $user_rights;
     // Get REDCap validation types
     $valTypes = getValTypes();
     // Array to place report attributes
     $reports = array();
     // If report_id is 0 (report doesn't exist), then return field defaults from tables
     if ($report_id === 0) {
         // || $report_id == 'ALL' || $report_id == 'SELECTED') {
         // Add to reports array
         $reports[$report_id] = getTableColumns('redcap_reports');
         // Pre-fill empty slots for limiters and fields
         $reports[$report_id]['fields'] = array();
         $reports[$report_id]['limiter_fields'] = array();
         $reports[$report_id]['filter_dags'] = array();
         //$reports[$report_id]['limiter_events'] = array();
         $reports[$report_id]['limiter_logic'] = "";
         $reports[$report_id]['user_access_users'] = array();
         $reports[$report_id]['user_access_roles'] = array();
         $reports[$report_id]['user_access_dags'] = array();
         $reports[$report_id]['output_dags'] = 0;
         $reports[$report_id]['output_survey_fields'] = 0;
         $reports[$report_id]['output_schedule_dates'] = array();
         $reports[$report_id]['output_survey_urls'] = array();
         // For "new" (to-be created) reports, set Record ID field as first field and first sorting field in report
         $reports[$report_id]['fields'] = array($Proj->table_pk);
         $reports[$report_id]['orderby_field1'] = $Proj->table_pk;
         $reports[$report_id]['orderby_sort1'] = 'ASC';
         // DDE: If user is DDE person 1 or 2, then limit to ONLY their records
         if ($double_data_entry && is_array($user_rights) && $user_rights['double_data'] != 0) {
             if ($reports[$report_id]['limiter_logic'] == '') {
                 $reports[$report_id]['limiter_logic'] = "ends_with([{$Proj->table_pk}], \"--{$user_rights['double_data']}\")";
             } else {
                 $reports[$report_id]['limiter_logic'] = "({$reports[$report_id]['limiter_logic']}) and ends_with([{$Proj->table_pk}], \"--{$user_rights['double_data']}\")";
             }
         }
         // Return array
         return $reports[$report_id];
     }
     $lrProjectData = array();
     $filterExpr = '[project_id] = ' . $Proj->project_id;
     if (is_numeric($report_id)) {
         $filterExpr .= " and [report_id] = {$report_id}";
     }
     $lrProjectData = REDCap::getData(LR_REPORT_DATA_PROJECT_ID, 'array', null, null, null, null, false, false, false, $filterExpr, false, false);
     // If no reports, then return empty array
     if (empty($lrProjectData)) {
         return array();
     }
     foreach ($lrProjectData as $eventId => $reportRecords) {
         foreach ($reportRecords as $rptRec) {
             $rId = $rptRec['report_id'];
             $reports[$rId]['report_id'] = $rId;
             $reports[$rId]['project_id'] = $rptRec['project_id'];
             $reports[$rId]['title'] = $rptRec['title'];
             $reports[$rId]['report_order'] = $rptRec['report_order'];
             $reports[$rId]['user_access'] = $rptRec['user_access'];
             $reports[$rId]['user_access_dags'] = json_decode($rptRec['user_access_dags'], true);
             $reports[$rId]['user_access_roles'] = json_decode($rptRec['user_access_roles'], true);
             $reports[$rId]['user_access_users'] = json_decode($rptRec['user_access_users'], true);
             $reports[$rId]['fields'] = json_decode($rptRec['fields'], true);
             $reports[$rId]['output_dags'] = $rptRec['output_dags'] === "on" ? "1" : "0";
             $reports[$rId]['output_survey_fields'] = $rptRec['output_survey_fields'] === "on" ? "1" : "0";
             $reports[$rId]['output_schedule_dates'] = json_decode($rptRec['output_schedule_dates'], true);
             $reports[$rId]['output_survey_urls'] = json_decode($rptRec['output_survey_urls'], true);
             $reports[$rId]['limiter_fields'] = json_decode($rptRec['limiter_fields'], true);
             $reports[$rId]['filter_dags'] = json_decode($rptRec['filter_dags'], true);
             $reports[$rId]['advanced_logic'] = $rptRec['advanced_logic'];
             $reports[$rId]['orderby_field1'] = $rptRec['orderby_field1'];
             $reports[$rId]['orderby_sort1'] = $rptRec['orderby_sort1'];
             $reports[$rId]['orderby_field2'] = $rptRec['orderby_field2'];
             $reports[$rId]['orderby_sort2'] = $rptRec['orderby_sort2'];
             $reports[$rId]['orderby_field3'] = $rptRec['orderby_field3'];
             $reports[$rId]['orderby_sort3'] = $rptRec['orderby_sort3'];
             $reports[$rId]['limiter_logic'] = "";
             // Will build below
         }
     }
     // Loop through all reports and build the filter logic into a single string
     foreach ($reports as $this_report_id => $rattr) {
         // Advanced logic
         if ($rattr['advanced_logic'] != '') {
             $reports[$this_report_id]['limiter_logic'] = $rattr['advanced_logic'];
         } elseif (!empty($rattr['limiter_fields'])) {
             foreach ($rattr['limiter_fields'] as $i => $attr) {
                 // Translate the limiter item into logic
                 $reports[$this_report_id]['limiter_logic'] .= ($attr['limiter_group_operator'] == 'AND' ? $i == 0 ? "(" : ") AND (" : " OR ") . self::translateLimiterItem($attr);
             }
             // Finish with ending parenthesis
             $reports[$this_report_id]['limiter_logic'] .= ")";
         }
         // DDE: If user is DDE person 1 or 2, then limit to ONLY their records by appending ends_with() onto limiter_logic
         if ($double_data_entry && is_array($user_rights) && $user_rights['double_data'] != 0) {
             if ($reports[$this_report_id]['limiter_logic'] == '') {
                 $reports[$this_report_id]['limiter_logic'] = "ends_with([{$Proj->table_pk}], \"--{$user_rights['double_data']}\")";
             } else {
                 $reports[$this_report_id]['limiter_logic'] = "({$reports[$this_report_id]['limiter_logic']}) and ends_with([{$Proj->table_pk}], \"--{$user_rights['double_data']}\")";
             }
         }
         // Double check to make sure that it truly has SELECTED user access
         if ($rattr['user_access'] == 'SELECTED' && empty($rattr['user_access_users']) && empty($rattr['user_access_roles']) && empty($rattr['user_access_dags'])) {
             $reports[$this_report_id]['user_access'] = 'ALL';
         }
         // Make sure that Order By fields are NOT checkboxes (because that doesn't make sense)
         if ($Proj->isCheckbox($reports[$this_report_id]['orderby_field3'])) {
             $reports[$this_report_id]['orderby_field3'] = $reports[$this_report_id]['orderby_sort3'] = '';
         }
         if ($Proj->isCheckbox($reports[$this_report_id]['orderby_field2'])) {
             $reports[$this_report_id]['orderby_field2'] = $reports[$this_report_id]['orderby_field3'];
             $reports[$this_report_id]['orderby_sort2'] = $reports[$this_report_id]['orderby_sort3'];
             $reports[$this_report_id]['orderby_field3'] = $reports[$this_report_id]['orderby_sort3'] = '';
         }
         if ($Proj->isCheckbox($reports[$this_report_id]['orderby_field1'])) {
             $reports[$this_report_id]['orderby_field1'] = $reports[$this_report_id]['orderby_field2'];
             $reports[$this_report_id]['orderby_sort1'] = $reports[$this_report_id]['orderby_sort2'];
             $reports[$this_report_id]['orderby_field2'] = $reports[$this_report_id]['orderby_field3'];
             $reports[$this_report_id]['orderby_sort2'] = $reports[$this_report_id]['orderby_sort3'];
             $reports[$this_report_id]['orderby_field3'] = $reports[$this_report_id]['orderby_sort3'] = '';
         }
     }
     // Return array of report(s) attributes
     if ($report_id == null) {
         return $reports;
     } else {
         return $reports[$report_id];
     }
 }
Ejemplo n.º 6
0
function deleteRecords($params)
{
    /*
    * Script will attempt to delete multiple records by idfield/idvalues (comma-delimited) and other name/value pair parameters provided
    * You will get an error if you provided invalid field names.
    
    ** REQUIRED PARAMS
    tablename - name of the table to delete
    idfield - name of the parameter to specify records to delete
    idvalues - values of idfield; could be comma-delimited list (formatted id string (id,id,id))
    
    ** OTHER PARAMS
    * name/value pairs to specify records to delete
    */
    $sendParams = array();
    // gets array of fields name for 'tablename'
    $columnsArray = getTableColumns($params['tablename']);
    // make sure we have a content id and tablename
    if (isset($params['idvalues']) && isset($params['tablename']) && isset($params['idfield'])) {
        $sql = "DELETE FROM `" . $params['tablename'] . "` ";
        if (in_array($params['idfield'], $columnsArray)) {
            // checks for misspelling of field name
            $sql .= " WHERE " . $params['idfield'] . " IN ( ";
        } else {
            die("Unknown field name '" . $params['idfield'] . "'.");
        }
        $manyvalues = explode(",", $params['idvalues']);
        foreach ($manyvalues as $value) {
            $sql .= " :singlevalue" . $value . ", ";
            $sendParams['singlevalue' . $value] = $value;
        }
        $sql = substr($sql, 0, strlen($sql) - 2);
        //remove last comma and space
        $sql .= " )";
        foreach ($params as $key => $value) {
            if ($key != 'action' && $key != 'tablename' && $key != 'idfield' && $key != 'idvalues') {
                if (in_array($key, $columnsArray)) {
                    $sql .= " AND " . $key . " = :" . $key;
                    $sendParams[$key] = $value;
                } else {
                    die("Unknown field name '{$key}'.");
                }
            }
        }
    } else {
        die("No tablename or id provided.");
    }
    // get the results
    if ($result = queryDatabase($sql, $sendParams)) {
        sendSuccess();
    } else {
        die("Query Failed:" . $result->errorInfo());
    }
}
Ejemplo n.º 7
0
    $result = mysqli_query($conn, $query);
    if (!$result) {
        $post_data = array('message' => 'no table found in sql database', 'comment' => 'No Attendance Plugin found on Moodle Host');
        $post_data = json_encode(array('error' => $post_data), JSON_FORCE_OBJECT);
        die($post_data);
    }
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (isset($_GET['method']) && $_GET['method'] != "") {
    switch ($_GET['method']) {
        case 'get_table_names':
            getTableNames($conn);
            break;
        case 'get_table_columns':
            if (isset($_GET['table_name']) && $_GET['table_name'] != "") {
                getTableColumns($conn, $_GET['table_name']);
            } else {
                $post_data = array('message' => 'missing parameters', 'comment' => 'require param [table_name]');
                $post_data = json_encode(array('error' => $post_data), JSON_FORCE_OBJECT);
                echo $post_data;
            }
            break;
        case 'get_table_data':
            if (isset($_GET['table_name']) && $_GET['table_name'] != "") {
                getTableData($conn, $_GET['table_name']);
            } else {
                $post_data = array('message' => 'missing parameters', 'comment' => 'require param [table_name]');
                $post_data = json_encode(array('error' => $post_data), JSON_FORCE_OBJECT);
                echo $post_data;
            }
            break;