private function reorder_customfields($customfields)
 {
     $fields = cms_utils::get_module('CGCalendar')->GetFields();
     $fields = cge_array::to_hash($fields, 'field_name');
     $func = function ($a, $b) use($fields) {
         if ($a['event_id'] < $b['event_id']) {
             return -1;
         }
         if ($a['event_id'] > $b['event_id']) {
             return 1;
         }
         $aa = $fields[$a['field_name']];
         $aa = $fields[$b['field_name']];
         if ($aa['field_order'] < $bb['field_order']) {
             return -1;
         }
         if ($aa['field_order'] > $bb['field_order']) {
             return 1;
         }
         // now compare by field value.
         if ($a['field_value'] < $b['field_value']) {
             return -1;
         }
         if ($a['field_value'] > $b['field_value']) {
             return -1;
         }
         return 0;
     };
     usort($customfields, $func);
 }
 public static function get_fielddefs()
 {
     if (cge_tmpdata::exists('cgfb_fielddefs')) {
         return cge_tmpdata::get('cgfb_fielddefs');
     }
     $db = cmsms()->GetDb();
     $query = 'SELECT * FROM ' . CGFEEDBACK_TABLE_FIELDDEFS . ' ORDER BY iorder';
     $tmp = $db->GetArray($query);
     if (is_array($tmp)) {
         for ($i = 0; $i < count($tmp); $i++) {
             $tmp[$i]['attribs'] = unserialize($tmp[$i]['attribs']);
             if (isset($tmp[$i]['attribs']['options'])) {
                 $t2 = cge_array::explode_with_key($tmp[$i]['attribs']['options'], '=', "\n");
                 $tmp[$i]['attribs']['options'] = array_flip($t2);
             }
         }
         $tmp = cge_array::to_hash($tmp, 'id');
         cge_tmpdata::set('cgfb_fielddefs', $tmp);
         return $tmp;
     }
 }
if (!$dbresult) {
    $smarty->assign('error', 1);
    $smarty->assign('message', $this->Lang('error_nocategories'));
} else {
    // this could probably be done with a for_each, but what the hell
    while ($row2 = $dbresult->FetchRow()) {
        $categorylist[$row2['upload_category_name']] = $row2['upload_category_id'];
    }
}
// get custom field info.
$fields = array();
$query = 'SELECT * FROM ' . cms_db_prefix() . 'module_uploads_fielddefs ORDER BY iorder';
$tfields = $db->GetArray($query);
$query = 'SELECT * FROM ' . cms_db_prefix() . 'module_uploads_fieldvals WHERE upload_id = ?';
$tmp = $db->GetArray($query, array($params['upload_id']));
$tvals = cge_array::to_hash($tmp, 'fld_id');
for ($i = 0; $i < count($tfields); $i++) {
    $tfields[$i]['attrib'] = unserialize($tfields[$i]['attribs']);
    unset($tfields[$i]['attribs']);
    if (is_array($tvals) && isset($tvals[$tfields[$i]['id']])) {
        $tfields[$i]['value'] = $tvals[$tfields[$i]['id']]['value'];
    }
    switch ($tfields[$i]['type']) {
        case 'textarea':
            $tfields[$i]['input'] = $this->CreateTextArea(isset($tfields[$i]['attrib']['usewysiwyg']) && $tfields[$i]['attrib']['usewysiwyg'] == 1 && $this->GetPreference('allow_comment_wysiwyg', 0), $id, $tfields[$i]['value'], 'field_' . $tfields[$i]['id']);
            break;
        case 'dropdown':
        case 'multiselect':
            if (isset($tfields[$i]['attrib']['options'])) {
                $tmp = explode("\n", $tfields[$i]['attrib']['options']);
                $tmp2 = array();
         }
         $query = "SELECT A.id,";
         $flds = array();
         $conds = array();
         for ($i = 0; $i < count($viewprops); $i++) {
             $prop = $viewprops[$i];
             $nm = 'j' . $i;
             $flds[] = "{$nm}.data as {$prop}";
             $conds[] = cms_db_prefix() . "module_feusers_properties AS {$nm} ON A.id = {$nm}.userid AND ({$nm}.title = '{$prop}')";
         }
         $query .= implode(',', $flds) . ' FROM ' . cms_db_prefix() . 'module_feusers_users A';
         $query .= ' LEFT JOIN ' . implode(' LEFT JOIN ', $conds);
         $query .= ' WHERE A.id IN (' . implode(',', $uids) . ')';
         $dbr = $db->Execute('SET sql_big_selects = 1');
         $tmp = $db->GetArray($query);
         $extraprops = cge_array::to_hash($tmp, 'id');
     }
 }
 $rowarray = array();
 $rowclass = "row1";
 global $gCms;
 $smarty->assign('numusers', $numusers);
 if ($this->GetPreference('username_is_email')) {
     $smarty->assign('usernametext', $this->Lang('prompt_email'));
 } else {
     $smarty->assign('usernametext', $this->Lang('username'));
 }
 $smarty->assign('emailtext', $this->Lang('email'));
 $smarty->assign('statustext', $this->Lang('status'));
 $smarty->assign('createdtext', $this->Lang('created'));
 $smarty->assign('expirestext', $this->Lang('expires'));
        } else {
            $onerow->iconurl = $imgpath . 'unknown.png';
        }
        $onerow->description = $row['upload_description'];
        $onerow->ip = $row['upload_ip'];
        $onerow->size = intval($row['upload_size'] / 1024.0 + 0.5);
        $onerow->date = $row['upload_date'];
        $query = 'SELECT A.id,A.name,A.type,B.upload_id,B.value 
              FROM ' . cms_db_prefix() . 'module_uploads_fielddefs A 
              LEFT JOIN ' . cms_db_prefix() . 'module_uploads_fieldvals B 
                ON A.id = B.fld_id 
             WHERE B.upload_id = ? AND A.public = 1
             ORDER BY A.iorder ASC';
        $tmp = $db->GetArray($query, array($row['upload_id']));
        if ($tmp) {
            $hash = cge_array::to_hash($tmp, 'name');
            $onerow->fieldvals = array();
            foreach ($hash as $k => $v) {
                $onerow->fieldvals[$k] = $v['value'];
            }
            $onerow->fields = $hash;
        }
        $rowarray[] = $onerow;
    }
    $smarty->assign('items', $rowarray);
    $smarty->assign('itemcount', count($rowarray));
}
// Display the populated template
if ($params['mode'] != 'select') {
    echo $this->ProcessTemplateFromDatabase($template);
}
}
$parms = $params;
$parms['feedback_origpage'] = $returnid;
$data = array();
while ($dbr && ($row = $dbr->FetchRow())) {
    $prettyurl = "feedback/detail/{$row['id']}/{$detailpage}/";
    $prettyurl .= munge_string_to_url(substr($row['title'], 0, 30));
    $parms['cid'] = $row['id'];
    $row['detail_url'] = $this->CreateURL($id, 'detail', $detailpage, $parms, 0, $prettyurl);
    $sql = 'SELECT * FROM ' . CGFEEDBACK_TABLE_FIELDVALS . ' WHERE comment_id = ?';
    $tmp = $db->GetArray($sql, array($row['id']));
    if (is_array($tmp) && is_array($fields)) {
        for ($i = 0; $i < count($tmp); $i++) {
            $tmp[$i] = array_merge($tmp[$i], $fields[$tmp[$i]['field_id']]);
        }
        $row['fields'] = cge_array::to_hash($tmp, 'name');
    }
    $tmp = $fields;
    $data[] = $row;
}
#
# Give everything to smarty
#
$config = $gCms->GetConfig();
$path = $config['root_url'] . '/modules/' . $this->GetName() . '/images/';
$tmp = array('img_on' => $path . 'star.gif', 'img_off' => $path . 'starOff.gif', 'img_half' => $path . 'starHalf.gif');
$smarty->assign('rating_imgs', $tmp);
$smarty->assign('total_records', $total_records);
$smarty->assign('pagecount', $pagecount);
$smarty->assign('pagenum', $pagenum);
$parms = $params;
 public function check_extrafiles()
 {
     // walk the directory, generate the key, see if there are any extra files
     $dir = $this->_mod->GetModulePath();
     $cdata = $this->parse_cdat();
     $cdata = \cge_array::to_hash($cdata, 'file');
     $tmpdata = array();
     $this->walk_directory($dir, function ($path) use(&$tmpdata, $cdata) {
         $key = $this->get_checksum_key($path);
         if (!isset($cdata[$key])) {
             $tmpdata[] = $path;
         }
     });
     if (count($tmpdata)) {
         return $tmpdata;
     }
 }
 public function handle_file()
 {
     $uploads = cms_utils::get_module('Uploads');
     // validate the data.
     if (!isset($this->_data['src'])) {
         throw UploadsException('Invalid attributes... no source file set');
     }
     if (!$this->_category) {
         throw UploadsException('Invalid/Null upload category speciried');
     }
     if (!isset($this->_data['summary'])) {
         $sumamry = basename($this->_data['src']);
         $this->set_summary($summary);
     }
     if (!isset($this->_data['description'])) {
         $this->_data['description'] = '';
     }
     if (!isset($this->_data['key'])) {
         $this->_data['key'] = '';
     }
     if (!isset($this->_data['author'])) {
         // author hasn't been previously set.
         // try to find something we can use.
         global $CMS_ADMIN_PAGE;
         $author = 'Anonymous';
         if (isset($CMS_ADMIN_PAGE)) {
             // it's an admin action... get the currently logged in username
             $uid = get_userid(FALSE);
             if ($uid) {
                 $userops = cmsms()->GetUserOperations();
                 $user = $userops->LoadUserById($uid);
                 if ($user) {
                     $author = $user->username;
                 }
             }
         } else {
             $feu = cms_utils::get_module('FrontEndUsers');
             if ($feu) {
                 $tmp = $feu->LoggedInName();
                 if ($tmp) {
                     $author = $tmp;
                 }
             }
         }
         $this->_data['author'] = $author;
     }
     $db = cmsms()->GetDb();
     $destfile = $this->get_destfile();
     $existing_fileid = null;
     if (file_exists($destfile) && !isset($this->_data['allow_overwrite'])) {
         // not allowing overwrite
         throw new UploadsException('Destination File Exists: ' . $destfile);
     } else {
         if (file_exists($destfile)) {
             // allowing overwrite... try to find a file id.
             $query = 'SELECT upload_id FROM ' . cms_db_prefix() . 'module_uploads 
               WHERE upload_name = ? AND upload_category_id = ?';
             $existing_fileid = $db->GetOne($query, basename($destname), $this->_category['uploads_category_id']);
         }
     }
     // see if we're gonna watermark
     $_created = array();
     $can_unlink = FALSE;
     $srcfile = $this->_data['src'];
     if (isset($this->_data['do_watermark'])) {
         $dn = dirname($destfile);
         $fn = basename($destfile);
         $wmname = cms_join_path($dn, 'wm_', $fn);
         $wmobj = cge_setup::get_watermarker();
         $res = $wmobj->create_watermarked_image($srcfile, $wmname);
         if ($res !== FALSE) {
             $can_unlink = TRUE;
             $srcfile = $wmname;
             $_created[] = $srcfile;
         }
     }
     // see if we're gonna thumbnail.
     $thumb_name = '';
     if (isset($this->_data['do_thumbnail'])) {
         $thumb_name = basename($destname);
         $dn = dirname($destname);
         $thumbfile = cms_join_path($dn, 'thumb_' . $thumb_name);
         $uploads->imageTransform($srcfile, $thumbfile);
         $_created[] = $thumbfile;
     } else {
         if (isset($this->_data['thumbnail'])) {
             $thumb_name = basename($destname);
             $dn = dirname($destname);
             $thumbfile = cms_join_path($dn, 'thumb_' . $thumb_name);
             @copy($this->_data['thumbnail'], $thumbfile);
             $_created[] = $thumbfile;
         }
     }
     // do the copy.
     @unlink($destfile);
     @copy($srcfile, $destfile);
     $_created[] = $destfile;
     // do the insert or update
     $dbr = '';
     if (!$existing_fileid) {
         $existing_fileid = $db->GenId(cms_db_prefix() . 'module_uploads_seq');
         // insert
         $query = 'INSERT INTO ' . cms_db_prefix() . 'module_uploads
               (upload_id,upload_category_id,upload_name,upload_author,
                upload_summary,upload_description,upload_ip,upload_size,
                upload_date, upload_key, upload_thumbnail)
               VALUES (?,?,?,?,?,?,?,?,NOW(),?,?)';
         $dbr = $db->Execute($query, array($existing_fileid, $this->_category['upload_category_id'], basename($destfile), $this->_data['author'], $this->_data['summary'], $this->_data['desciption'], cge_utils::get_real_ip(), filesize($this->_data['src']), $this->_data['key'], $thumb_name));
     } else {
         // update... delete custom fields.
         $query = 'DELETE FROM ' . cms_db_prefix() . 'module_uploads_fieldvals WHERE upload_id = ?';
         $dbr = $db->Execute($query, array($existing_fileid));
         $query = 'UPDATE ' . cms_db_prefix() . 'module_uploads
               SET upload_name = ?, upload_author = ?,
                   upload_summary = ?, upload_description = ?,
                   upload_ip = ?, upload_size = ?, upload_date = NOW(),
                   upload_key = ?, upload_thumbnail = ?
              WHERE upload_id = ?';
         $dbr = $db->Execute($query, array(basename($destfile), $this->_data['author'], $this->_data['summary'], $this->_data['desc'], cge_array::get_real_ip(), filesize($destfile), $this->_data['key'], $thumb_name, $existing_fileid));
     }
     if (!$dbr) {
         foreach ($_created as $one) {
             @unlink($one);
         }
         throw new UploadsException('Database operation failed: ' . $db->sql . ' -- ' . $db->ErrorMsg());
     }
     $fields = '';
     $query = 'SELECT id,name FROM ' . cms_db_prefix() . 'module_uploads_fielddefs ORDER BY iorder';
     $tmp = $db->GetArray($query);
     if (!is_array($tmp)) {
         $fields = cge_array::to_hash($tmp, 'name');
     }
     if (is_array($fields) && isset($this->_data['fields'])) {
         // do the custom fields.
         $iquery = 'INSERT INTO ' . cms_db_prefix() . 'module_uploads_fieldvals 
              (upload_id, fld_id, value) VALUES (?,?,?)';
         foreach ($this->_data['fields'] as $key => $value) {
             if (!isset($fields[$key])) {
                 continue;
             }
             $field_id = $fields[$key]['id'];
             $db->Execute($iquery, array($existing_fileid, $ield_id, $value));
         }
     }
     // add something to the audit log.
     audit($existing_fileid, $uploads->GetName(), 'Uploaded file ' . basename($destfile));
     // and we're done...
     return $existing_fileid;
 }
 private function _get_groups()
 {
     if (!is_array($this->_groups)) {
         $feu = cge_utils::get_module('FrontEndUsers');
         $tmp = $feu->GetGroupListFull();
         if (is_array($tmp) && count($tmp)) {
             $this->_groups = cge_array::to_hash($tmp, 'groupname');
         }
     }
     return $this->_groups;
 }
        $this->Redirect($id, 'changesettings', $returnid, $params);
    }
}
// get property definitions
$defnsbyname = $this->GetPropertyDefns();
// Get member groups
$groups = $this->GetMemberGroupsArray($uid);
// Get group property relations into a union.
$properties = array();
$tmp = array();
foreach ($groups as $onegroup) {
    $proprelations = $this->GetGroupPropertyRelations($onegroup['groupid']);
    $tmp = RRUtils::array_merge_by_name_required($tmp, $proprelations);
    uasort($tmp, array('cge_array', 'compare_elements_by_sortorder_key'));
}
$properties = cge_array::to_hash($tmp, 'name');
$userprops = $this->GetUserProperties($uid);
// do validation of the fields.
foreach ($properties as $propname => $prop) {
    $fldtype = $defnsbyname[$propname]['type'];
    $required = $prop['required'] == 2;
    switch ($fldtype) {
        case '0':
            /* text */
            if ($required) {
                if (!isset($params['feu_input_' . $propname]) || empty($params['feu_input_' . $propname])) {
                    $params['error'] = 1;
                    $params['message'] = $this->Lang('error_requiredfield', $defnsbyname[$propname]['prompt']);
                    $this->Redirect($id, 'changesettings', $returnid, $params);
                }
            }
Esempio n. 11
0
 public static function get_categories($by_id = FALSE)
 {
     if (!is_array(self::$_cached_categories)) {
         $db = cmsms()->GetDb();
         self::$_cached_categories = array();
         $mod = \cms_utils::get_module(MOD_CGCALENDAR);
         $categories_table_name = $mod->categories_table_name;
         $sql = "SELECT * FROM {$mod->categories_table_name} ORDER BY category_order, category_name";
         self::$_cached_categories = $db->GetArray($sql);
     }
     if ($by_id) {
         return \cge_array::to_hash(self::$_cached_categories, 'category_id');
     }
     return self::$_cached_categories;
 }
} else {
    $delimiter = isset($params['delimiter']) ? trim($params['delimiter']) : $this->GetPreference('import_delimiter', ',');
    $this->SetPreference('import_delimiter', $delimiter);
    $user_id = get_userid();
    // get a category map.
    $sql = 'SELECT category_id, category_name FROM ' . $this->categories_table_name;
    $rs = $db->Execute($sql);
    $cat = array();
    while ($rs && ($row = $rs->FetchRow())) {
        $cat[$row['category_name']] = $row['category_id'];
    }
    // get a field map.
    $fields = array();
    $tmp = $this->GetFields();
    if (is_array($tmp) && count($tmp)) {
        $fields = cge_array::to_hash($tmp, 'field_name');
    }
    // open the file
    $handle = fopen($_FILES[$id . 'csv_file']['tmp_name'], "r");
    if ($handle === false) {
        $this->SetError('error_cantopenfile');
        $this->RedirectToTab($id);
    }
    // get the first line.
    $linenum = 1;
    $line = _getline($handle);
    if (feof($handle) || $line == '') {
        $this->SetError($this->Lang('error_csvinvalidfirstline'));
        $this->RedirectToTab($id);
    }
    // parse the first line into a field map.
 private function _get_groupinfo()
 {
     if (!is_array($this->_groupinfo_cache)) {
         $db = $this->GetDb();
         $query = 'SELECT * FROM ' . cms_db_prefix() . 'module_feusers_groups';
         $dbr = $db->GetArray($query);
         if (is_array($dbr)) {
             $this->_groupinfo_cache = cge_array::to_hash($dbr, 'id');
         }
     }
 }
if (!$order_obj) {
    return;
}
if ($order_obj->get_status() != ORDERSTATUS_SUBSCRIBED && $order_obj->get_status() != ORDERSTATUS_PAID) {
    // don't do anything unless we're dealing with a subscribed order.
    return;
}
// get the list of packages
$pkgs = '';
$query = 'SELECT * FROM ' . cms_db_prefix() . 'module_selfreg_paidpkgs';
$tmp = $db->GetArray($query);
if (!$tmp) {
    return;
    // no packages
}
$pkgs = cge_array::to_hash($tmp, 'id');
// find the line item with a SelfReg Subscription.
for ($s = 0; $s < $order_obj->count_destinations(); $s++) {
    $shipping = $order_obj->get_shipping($s);
    for ($i = 0; $i < $shipping->count_all_items(); $i++) {
        $item = $shipping->get_item($i);
        if ($item->get_source() != $this->GetName()) {
            continue;
        }
        if ($item->get_item_type() != line_item::ITEMTYPE_SERVICE) {
            continue;
        }
        //if( !$item->is_subscription() ) continue;
        $temp_uid = $item->get_item_id();
        $sku = $item->get_sku();
        if (!$sku) {
// get field definitions.
$defns = $this->GetPropertyDefns();
// get the property relations for the selected group(s).
$parms1 = cge_array::explode_with_key($params['step1_params']);
$groupprops = array();
$groupids = array();
foreach ($parms1 as $key => $value) {
    if (startswith($key, 'memberof_')) {
        $gid = (int) substr($key, strlen('memberof_'));
        $groupids[] = $gid;
        $relns = $this->GetGroupPropertyRelations($gid);
        $groupprops = RRUtils::array_merge_by_name_required($groupprops, $relns);
        uasort($groupprops, array('cge_array', 'compare_elements_by_sortorder_key'));
    }
}
$groupprops = cge_array::to_hash($groupprops, 'name');
// get the field info
$fieldlist = array();
foreach ($params as $k => $v) {
    if (preg_match('/^hidden_/', $k)) {
        $fldname = substr($k, strlen('hidden_'));
        $fieldlist[$fldname] = $v;
    }
}
// now merge form values for each of the fields
foreach ($groupprops as $fldname => $reln) {
    $v = '';
    switch ($defns[$fldname]['type']) {
        case '6':
            // image
            // we'll handle setting the value for this below.... this is just a placeholder.
Esempio n. 16
0
    @trigger_error($this->GetName() . ' detail view: invalid comment id');
    return;
}
#
# Get the data
#
$data = $db->GetRow($query, array($cid, CGFEEDBACK_STATUS_PUBLISHED));
if (!$data) {
    return;
}
$query = 'SELECT A.name,A.type,B.value FROM ' . CGFEEDBACK_TABLE_FIELDDEFS . ' A 
          LEFT JOIN ' . CGFEEDBACK_TABLE_FIELDVALS . ' B 
          ON A.id = B.field_id WHERE B.comment_id = ?';
$fields = $db->GetArray($query, array($cid));
if (is_array($fields)) {
    $data['fields'] = cge_array::to_hash($fields, 'name');
}
#
# Give everything to smarty
#
$config = $gCms->GetConfig();
$path = $config['root_url'] . '/modules/' . $this->GetName() . '/images/';
$tmp = array('img_on' => $path . 'star.gif', 'img_off' => $path . 'starOff.gif', 'img_half' => $path . 'starHalf.gif');
$smarty->assign('rating_imgs', $tmp);
$smarty->assign('onecomment', $data);
#
# Display the template
#
echo $this->ProcessTemplateFromDatabase($thetemplate);
#
# EOF
Esempio n. 17
0
if (!empty($data['upload_thumbnail'])) {
    $tnfile = $this->_categoryPath($category['upload_category_path'] . '/' . $data['upload_thumbnail']);
    if (@file_exists($tnfile)) {
        $tnurl = $config['uploads_url'] . '/' . $category['upload_category_path'] . '/' . $data['upload_thumbnail'];
        $row->thumbnail_url = $tnurl;
    }
}
$query = 'SELECT A.id,A.name,A.type,B.upload_id,B.value 
              FROM ' . cms_db_prefix() . 'module_uploads_fielddefs A 
              LEFT JOIN ' . cms_db_prefix() . 'module_uploads_fieldvals B 
                ON A.id = B.fld_id 
             WHERE B.upload_id = ? AND A.public = 1
             ORDER BY A.iorder ASC';
$tmp = $db->GetArray($query, array($params['upload_id']));
if ($tmp) {
    $row->fields = cge_array::to_hash($tmp, 'name');
}
switch ($params['mode']) {
    case 'link':
        echo $this->CreateFrontendLink($id, $returnid, 'getfile', $row->name, array('upload_id' => $params['upload_id']), '', false, true, '', false, $this->_getFileURL($row->id, $row->name));
        return;
    case 'url':
        echo $row->download_url;
        return;
    default:
        $items = array();
        $items[] = $row;
        $smarty->assign('items', $items);
        // backwards compatibility.
        $smarty->assign('entry', $row);
}