Ejemplo n.º 1
0
            $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();
                foreach ($tmp as $one) {
                    $key = $value = $one;
                    if (strpos($one, '=') !== FALSE) {
                        list($key, $value) = explode('=', trim($one), 2);
                    }
                    $tmp2[trim($value)] = trim($key);
                }
                $tfields[$i]['attrib']['options'] = $tmp2;
                $tfields[$i]['value'] = cge_array::smart_explode($tfields[$i]['value']);
            }
            break;
    }
    $fields[$tfields[$i]['id']] = $tfields[$i];
}
// populate the template
$smarty->assign("startform", $this->CreateFormStart($id, 'do_editupload', $returnid, 'post', 'multipart/form-data'));
// todo check this to see if there are spaces in the name
$addtext_thumbnail = 'title="' . $this->Lang('title_create_thumbnail') . '"';
// $smarty->assign ('fix',
// 		 $this->CreateInputSubmit ($id, 'fix', $this->Lang('fixme')));
$smarty->assign('thumbnail', $this->CreateInputSubmit($id, 'thumbnail', $this->Lang('create_thumbnail'), $addtext_thumbnail));
$smarty->assign('submit', $this->CreateInputSubmit($id, 'submit', $this->Lang('submit')));
$smarty->assign('cancel', $this->CreateInputSubmit($id, 'cancel', $this->Lang('cancel')));
$smarty->assign('endform', $this->CreateFormEnd());
 public static function cge_setlist($params, $smarty)
 {
     $name = get_parameter_value($params, 'array');
     $name = get_parameter_value($params, 'name', $name);
     $key = get_parameter_value($params, 'key');
     $val = get_parameter_value($params, 'value');
     $name = trim($name);
     $key = trim($key);
     if (!$name || !isset($params['value'])) {
         return;
     }
     $parts = explode('.', $name);
     $data = array();
     if (!is_array($parts) || count($parts) == 0) {
         return;
     }
     if ($key) {
         $parts[] = $key;
     }
     $smarty = CmsApp::get_instance()->GetSmarty();
     $name = $parts[0];
     $data = $smarty->get_template_vars($name);
     if (!$data) {
         $data = array();
     }
     if (!is_array($data)) {
         $data = array($data);
     }
     // {cge_setlist name='a.b.c.d' value='55'}
     $ref =& $data;
     $i = 0;
     for ($i = 1; $i < count($parts) - 1; $i++) {
         if (!isset($ref[$parts[$i]]) || !is_array($ref[$parts[$i]])) {
             if ($i < count($parts) - 1) {
                 $ref[$parts[$i]] = array();
             }
         }
         $ref =& $ref[$parts[$i]];
     }
     // expect a list of values... may contain key/value pairs
     if (strpos($val, '::') === FALSE) {
         $ref[$parts[$i]] = $val;
     } else {
         $tmp = cge_array::smart_explode($val, '||');
         if (is_array($tmp) && count($tmp)) {
             $ref[$parts[$i]] = array();
             for ($j = 0; $j < count($tmp); $j++) {
                 $k = '';
                 $v = $tmp[$j];
                 if (strpos($v, '::') !== FALSE) {
                     list($k, $v) = explode('::', $tmp[$j], 2);
                 }
                 if ($k) {
                     $k = trim(trim($k, '"'));
                 }
                 if ($v) {
                     $v = trim(trim($v, '"'));
                 }
                 if ($k) {
                     $ref[$parts[$i]][$k] = $v;
                 } else {
                     $ref[$parts[$i]][] = $v;
                 }
             }
         }
     }
     // put the data back
     $smarty->assign($name, $data);
     // done.
 }
 }
 // now begin importing.
 $errors = array();
 $imported = 0;
 while (!feof($handle)) {
     $start_time = null;
     $end_time = null;
     $all_day = false;
     $start_time_ts = null;
     $end_time_ts = null;
     $line = _getline($handle);
     $linenum++;
     if (!$line) {
         continue;
     }
     $data = cge_array::smart_explode($line, $delimiter);
     $event_id = $db->GenID($this->events_table_name . "_seq");
     $tmp = _map_field($fieldmap, $data, 'start time');
     if ($tmp == 'NULL' || $tmp == '') {
         // no start time is an error.
         $errors[] = $this->Lang('error_csv_insert', $linenum) . ' 1';
     } else {
         $start_time_ts = strtotime($tmp);
         if (!$start_time_ts) {
             $start_time_ts = $db->UnixTimeStamp($tmp);
         }
         if (!$start_time_ts) {
             $errors[] = $this->Lang('error_csv_insert', $linenum) . ' 1a';
             continue;
         }
     }
//
// 6.  Begin Importing Records
//
$lineno = 1;
// we've already read one line
$errors = 0;
$added = 0;
while (!feof($handle)) {
    //
    // 6.1 Get a line, and convert it into fields
    $line = _getline($handle);
    $lineno++;
    if ($line == '') {
        continue;
    }
    $fields = cge_array::smart_explode($line);
    $importerror = FALSE;
    //
    // 6.2 get the username, password and expires data
    //     and add the user
    $uprops = array();
    $userid = '';
    $username = trim($fields[$fieldmap['username']], '\\"');
    $password = '******';
    // todo, customizable
    $passhash = '';
    $expires = strtotime("+10 years");
    // todo, customizable
    if ($have_password) {
        // expect plaintext password
        $password = trim($fields[$fieldmap['password']], '\\"');
 function _CreateFrontendUser($tmpid, $group_id, $username, $password, $expires = '', $do_md5 = true)
 {
     global $gCms;
     $db = $gCms->GetDb();
     $feusers = $this->GetModuleInstance('FrontEndUsers');
     if (!$feusers) {
         return array(FALSE, $this->Lang('error_nofeusersmodule'));
     }
     $query = 'SELECT * FROM ' . cms_db_prefix() . 'module_selfreg_users
            WHERE id = ?';
     $row = $db->GetRow($query, array($tmpid));
     if (!$row) {
         return array(FALSE, $this->Lang('error_usernotfound'));
     }
     if ($expires == '') {
         $timeperiod = $feusers->GetPreference('expireage_months', 120);
         $expires = strtotime("+{$timeperiod} months", time());
     }
     if ($row['overwrite_uid']) {
         // we're overwriting a user account
         $result = $feusers->SetUser($row['overwrite_uid'], $username, $password, $expires, $do_md5);
         if ($result[0] == false) {
             return array(FALSE, $result[1]);
         }
     } else {
         $result = $feusers->AddUser($username, $password, $expires, $do_md5);
         if ($result[0] == false) {
             return array(FALSE, $result[1]);
         }
     }
     $uid = $result[1];
     $feusers->SetEncryptionKey($uid, 1);
     $gid = $this->GetPreference('default_group', -1);
     if ($gid != -1) {
         // a default group is required,
         // so add him to that group
         if (!$feusers->AssignUserToGroup($uid, $gid)) {
             return array(FALSE, $this->Lang('warning_couldnotaddgroup'));
         }
     }
     // and add the user to whatever group specified in the groups parameter
     if ($group_id) {
         if (!$feusers->AssignUserToGroup($uid, $group_id)) {
             return array(FALSE, $this->Lang('warning_couldnotaddgroup'));
         }
     }
     // he's in.... he's in... now just add his properties
     $q = "SELECT * FROM " . cms_db_prefix() . "module_selfreg_properties\n          WHERE user = ?";
     $dbresult = $db->Execute($q, array($tmpid));
     if (!$dbresult) {
         return array(FALSE, $this->Lang('error_dberror'));
     }
     while ($row = $dbresult->FetchRow()) {
         $feusers->SetUserPropertyFull($row['title'], $row['data'], $uid);
     }
     // send an event
     $this->SendEvent('onUserRegistered', array('username' => $username, 'id' => $uid));
     // and notify the administrator
     // if the admin wants notifications.
     // off we go.
     if ($this->GetPreference('notify_on_registration')) {
         $cmsmailer = $this->GetModuleInstance('CMSMailer');
         if (!$cmsmailer) {
             return array(FALSE, $this->Lang('error_nocmsmailermodule'));
         }
         $tmp = $this->GetPreference('send_emails_to');
         if ($tmp) {
             $list = cge_array::smart_explode($tmp);
             foreach ($list as $one) {
                 $cmsmailer->AddAddress($one);
             }
             $cmsmailer->SetSubject('A new user has registered on ' . $gCms->config['root_url']);
             $msg = 'A new user (' . $username . ' with uid ' . $uid . ') has completed registration to your site. you should check this user out and validate that the information provided is as complete and valid as possible.';
             $cmsmailer->SetBody($msg);
             $cmsmailer->IsHTML(false);
             // we're not sending an html mail
             $cmsmailer->Send();
         }
     }
     $this->Audit(0, $this->Lang('friendlyname'), $this->Lang('info_userverified') . ": " . $username);
     return array(TRUE, $uid);
 }