예제 #1
0
/**
*   Import events from the Calendar plugin to evList.
*   This function checks that the event ID isn't already in use to avoid
*   re-importing events.
*
*   @return integer     0 = success, -1 = event table missing, >0 = error count
*/
function evlist_import_calendar_events()
{
    global $_TABLES, $LANG_EVLIST;
    if (!isset($_TABLES['events']) || empty($_TABLES['events'])) {
        return -1;
    }
    $errors = 0;
    // Keep track of errors
    $result = DB_query("SELECT * FROM {$_TABLES['events']}", 1);
    while ($A = DB_fetchArray($result, false)) {
        if (empty($A['timestart'])) {
            $A['timestart'] = '00:00:00';
        }
        list($s_hour, $s_min, $s_sec) = explode(':', $A['timestart']);
        if (empty($A['timeend'])) {
            $A['timeend'] = '00:00:00';
        }
        list($e_hour, $e_min, $e_sec) = explode(':', $A['timeend']);
        $s_ampm = $s_hour == 0 || $s_hour > 12 ? 'pm' : 'am';
        $e_ampm = $e_hour == 0 || $e_hour > 12 ? 'pm' : 'am';
        $E = array('eid' => $A['eid'], 'title' => $A['title'], 'summary' => $A['description'], 'full_description' => '', 'date_start1' => $A['datestart'], 'date_end1' => $A['dateend'], 'starthour1' => $s_hour, 'startminute1' => $s_min, 'start_ampm' => $s_ampm, 'endhour1' => $e_hour, 'endminute1' => $e_min, 'end_ampm' => $e_ampm, 'url' => $A['url'], 'street' => $A['address1'], 'city' => $A['city'], 'province' => $A['state'], 'postal' => $A['zipcode'], 'allday' => $A['allday'] == 1 ? 1 : 0, 'location' => $A['location'], 'owner_id' => (int) $A['owner_id'], 'group_id' => (int) $A['group_id'], 'perm_owner' => (int) $A['perm_owner'], 'perm_group' => (int) $A['perm_group'], 'perm_members' => (int) $A['perm_members'], 'perm_anon' => (int) $A['perm_anon'], 'show_upcoming' => 1, 'status' => $A['status'] == 1 ? 1 : 0, 'hits' => (int) $A['hits'], 'cal_id' => 1);
        // We'll let the event object handle most things, saving the
        // event and detail records.
        // Create the event object, while checking if the eid exists
        $Ev = new evEvent($A['eid']);
        if ($Ev->id != '') {
            // Oops, dup ID, must already be done.
            continue;
        }
        // Skip possible duplicates
        // Force it to be a new event even though we have an event ID
        $Ev->isNew = true;
        if ($Ev->Save($E, 'evlist_events', true) !== '') {
            COM_errorLog(sprintf($LANG_EVLIST['err_import_event'], $A['eid']));
            $errors++;
            continue;
            // This one failed, keep trying the others
        }
        // PITA, but perms don't get updated right by Save().  We can do this
        // or convert them to form-style checkbox values before saving. This
        // seems simpler
        $sql = "UPDATE {$_TABLES['evlist_events']} SET\n                    perm_owner   = '{$E['perm_owner']}',\n                    perm_group   = '{$E['perm_members']}',\n                    perm_members = '{$E['perm_anon']}',\n                    perm_anon    = '{$E['perm_anon']}'\n                WHERE id='{$Ev->id}'";
        //echo $sql;die;
        DB_query($sql, 1);
        if (DB_error()) {
            $error = 1;
            continue;
        }
    }
    return $errors;
}
예제 #2
0
파일: event.php 프로젝트: matrox66/evlist
             $det_id = $R->det_id;
             $sql = "UPDATE {$_TABLES['evlist_repeat']}\n                SET rp_det_id = '{$R->det_id}'\n                WHERE rp_date_start >= '{$R->date_start}'\n                    AND rp_ev_id = '{$R->ev_id}'";
             DB_query($sql);
         }
     }
     if (isset($_GET['admin'])) {
         echo COM_refresh(EVLIST_ADMIN_URL);
         exit;
     }
     break;
 case 'saveevent':
     USES_evlist_class_event();
     $eid = isset($_POST['eid']) && !empty($_POST['eid']) ? $_POST['eid'] : '';
     $table = empty($eid) ? 'evlist_submissions' : 'evlist_events';
     $Ev = new evEvent($eid);
     $errors = $Ev->Save($_POST, $table);
     if (!empty($errors)) {
         $content .= '<span class="alert"><ul>' . $errors . '</ul></span>';
         $content .= $Ev->Edit();
         $view = 'none';
     } else {
         $view = 'home';
         if ($Ev->table == 'evlist_submissions') {
             $msg = 9;
         } else {
             $msg = 2;
         }
     }
     break;
 case 'delevent':
     USES_evlist_class_event();
예제 #3
0
파일: index.php 프로젝트: matrox66/evlist
/**
*   Import events from a CSV file into the database.
*
*   @return string      Completion message
*/
function EVLIST_importEvents()
{
    global $_CONF, $_TABLES, $LANG_EVLIST, $_USER;
    // Setting this to true will cause import to print processing status to
    // webpage and to the error.log file
    $verbose_import = true;
    $retval = '';
    // First, upload the file
    USES_class_upload();
    $upload = new upload();
    $upload->setPath($_CONF['path_data']);
    $upload->setAllowedMimeTypes(array('text/plain' => '.txt, .csv', 'application/octet-stream' => '.txt, .csv'));
    $upload->setFileNames('evlist_import_file.txt');
    $upload->setFieldName('importfile');
    if ($upload->uploadFiles()) {
        // Good, file got uploaded, now install everything
        $filename = $_CONF['path_data'] . 'evlist_import_file.txt';
        if (!file_exists($filename)) {
            // empty upload form
            $retval = $LANG_EVLIST['err_invalid_import'];
            return $retval;
        }
    } else {
        // A problem occurred, print debug information
        $retval .= $upload->printErrors(false);
        return $retval;
    }
    $fp = fopen($filename, 'r');
    if (!$fp) {
        $retval = $LANG_EVLIST['err_invalid_import'];
        return $retval;
    }
    USES_evlist_class_event();
    $success = 0;
    $failures = 0;
    // Set owner_id to the current user and group_id to the default
    $owner_id = (int) $_USER['uid'];
    if ($owner_id < 2) {
        $owner_id = 2;
    }
    // last resort, use Admin
    $group_id = (int) DB_getItem($_TABLES['groups'], 'grp_id', 'grp_name="evList Admin"');
    if ($group_id < 2) {
        $group_id = 2;
    }
    // last resort, use Root
    while (($event = fgetcsv($fp)) !== false) {
        $Ev = new evEvent();
        $Ev->isNew = true;
        $i = 0;
        $A = array('date_start1' => $event[$i++], 'date_end1' => $event[$i++], 'time_start1' => $event[$i++], 'time_end1' => $event[$i++], 'title' => $event[$i++], 'summary' => $event[$i++], 'full_description' => $event[$i++], 'url' => $event[$i++], 'location' => $event[$i++], 'street' => $event[$i++], 'city' => $event[$i++], 'province' => $event[$i++], 'country' => $event[$i++], 'postal' => $event[$i++], 'contact' => $event[$i++], 'email' => $event[$i++], 'phone' => $event[$i++], 'cal_id' => 1, 'status' => 1, 'hits' => 0, 'recurring' => 0, 'split' => 0, 'time_start2' => '00:00:00', 'time_end2' => '00:00:00', 'owner_id' => $owner_id, 'group_id' => $group_id);
        if ($_CONF['hour_mode'] == 12) {
            list($hour, $minute, $second) = explode(':', $A['time_start1']);
            if ($hour > 12) {
                $hour -= 12;
                $am = 'pm';
            } elseif ($hour == 0) {
                $hour = 12;
                $am = 'am';
            } else {
                $am = 'am';
            }
            $A['start1_ampm'] = $am;
            $A['starthour1'] = $hour;
            $A['startminute1'] = $minute;
            list($hour, $minute, $second) = explode(':', $A['time_end1']);
            if ($hour > 12) {
                $hour -= 12;
                $am = 'pm';
            } elseif ($hour == 0) {
                $hour = 12;
                $am = 'am';
            } else {
                $am = 'am';
            }
            $A['end1_ampm'] = $am;
            $A['endhour1'] = $hour;
            $A['endminute1'] = $minute;
        }
        if ($A['time_start1'] == '00:00:00' && $A['time_end1'] == '00:00:00') {
            $A['allday'] = 1;
        } else {
            $A['allday'] = 0;
        }
        $msg = $Ev->Save($A);
        if (empty($msg)) {
            $successes++;
        } else {
            $failures++;
        }
    }
    return "{$successes} Succeeded<br />{$failures} Failed";
}