📄 event.php3
字号:
if( $return ) {$this->error .= " The event in question was deleted."; } return 0; } $temp_array = split( ":", $dummy[0] ); unset( $dummy ); $mailto = $temp_array[0] . "@" . $GLOBALS["config_domain"]; exec( $GLOBALS["config_getuidinfo"] . " $rejecter_id", $dummy, $err_num ); if( $err_num ) {$this->error = "Your e-mail address could not be retrieved."; if( $return ) {$this->error .= " The event in question was deleted."; } return 0; } $temp_array = split( ":", $dummy[0] ); unset( $dummy ); $mailfrom = $temp_array[0] . "@" . $GLOBALS["config_domain"]; $subject = "Event rejection"; $message = "The event that you submitted for the " . $GLOBALS["config_abbrvname"] . " Event Calendar" . ", as included below,\nwas rejected" . ($reason ? " for the following reason:\n" . $reason : "."); $message .= $this->returnEventText(); mail( $mailto, $subject, $message, "From: $mailfrom" ); return $return; } function deleteEvent() {// pretty self-explanatory if( !$this->verifyAction( "Delete" ) ) { $this->error = "Permissions check failed."; return 0; } if (!$db_conn = connectRWToCalendar()) { $this->error = $php_errormsg; return 0; } if(! $result_id = @pg_exec( $db_conn, "BEGIN WORK" ) ) { $this->error = $php_errormsg; $this->error .= " beginning work in delete."; return 0; } // If there's a modification to this event, update that event $query = "UPDATE srcEvent SET modify_id = " . ( $this->modify_id ? $this->modify_id : "NULL" ) . " WHERE modify_id = " . $this->event_id; if( !$result_id = @pg_exec( $db_conn, $query ) ) { $this->error = $php_errormsg; $this->error .= " QUERY= " . $query; @pg_exec( $db_conn, "ROLLBACK WORK" ); return 0; } if( $this->deleteEventWithConnection( $db_conn ) ) { if( !$result_id = @pg_exec( $db_conn, "COMMIT WORK" ) ) { $this->error = $php_errormsg; $this->error .= " while committing work in delete."; @pg_exec( $db_conn, "ROLLBACK WORK" ); return 0; } pg_close( $db_conn ); return 1; } else { pg_close( $db_conn ); return 0; } } function deleteEventWithConnection( $db_conn, $do_rollback = 1 ) {// delete the event using an existing connection,// allows deletion to be nested within another transaction $tables = array( "srcEvent", "srcAudienceList", "srcCategoryList", "srcWeekdayList", "srcIndex" ); for( $i = 0; $i < count( $tables ); $i++ ) { $query = "DELETE FROM " . $tables[$i] . " WHERE event_id = " . $this->event_id; if( !$result_id = @pg_exec( $db_conn, $query ) ) { $this->error = $php_errormsg; $this->error .= " QUERY= " . $query; if( $do_rollback ) { @pg_exec( $db_conn, "ROLLBACK WORK" ); } return 0; } } return 1; } function approveEvent( $new_approver ) {// updates the event with the new approver_id if (!$db_conn = connectRWToCalendar()) { $this->error = $php_errormsg; return 0; } if(! $result_id = @pg_exec( $db_conn, "BEGIN WORK" ) ) { $this->error = $php_errormsg; $this->error .= " beginning work in approve."; return 0; } // if this is a modification, remove the original event if( $this->modify_id ) { $original_event = new SRCEventFromEventID( $this->modify_id ); if( !$original_event->deleteEventWithConnection( $db_conn ) ) { $this->error = $original_event->error; return 0; } $this->modify_id = $original_event->modify_id; $query = "UPDATE srcEvent SET modify_id = " . ( $this->modify_id ? $this->modify_id : "NULL" ) . " WHERE event_id = " . $this->event_id; if( !$result_id = pg_exec( $db_conn, $query ) ) { $this->error = $php_errormsg; $this->error .= " QUERY= " . $query; pg_exec( $db_conn, "ROLLBACK WORK" ); return 0; } }// We only want to approve the event if it's no longer a modification// (so a long chain of modifications may have to be approved several times) if( !$this->modify_id ) { $query = "UPDATE srcEvent SET approver_id = " . $new_approver . "WHERE event_id = " . $this->event_id; if( !$result_id = @pg_exec( $db_conn, $query ) ) { $this->error = $php_errormsg; $this->error .= " QUERY= " . $query; @pg_exec( $db_conn, "ROLLBACK WORK" ); return 0; } } if( !$result_id = @pg_exec( $db_conn, "COMMIT WORK" ) ) { $this->error = $php_errormsg; $this->error .= " while committing work in approve."; @pg_exec( $db_conn, "ROLLBACK WORK" ); return 0; } pg_close( $db_conn ); // the rest doesn't apply if this is still a modification if( $this->modify_id ) { return 1; } $this->approver_id = $new_approver;// mail support to inform submitter of approval. exec( $GLOBALS["config_getuidinfo"] . " $this->submitter_id", $dummy, $err_num ); if( $err_num ) {$this->error = "The submitter's e-mail address could not be retrieved." . " The event was approved anyway."; return 0; } $temp_array = split( ":", $dummy[0] ); unset( $dummy ); $mailto = $temp_array[0] . "@" . $GLOBALS["config_domain"]; exec( $GLOBALS["config_getuidinfo"] . " $new_approver", $dummy, $err_num ); if( $err_num ) {$this->error = "Your e-mail address could not be retrieved." . " The event was approved anyway."; return 0; } $temp_array = split( ":", $dummy[0] ); unset( $dummy ); $mailfrom = $temp_array[0] . "@" . $GLOBALS["config_domain"]; $subject = "Event approval"; $message = "The event that you submitted for the " . $GLOBALS["config_abbrvname"] . " Event Calendar" . ", as included below,\nwas approved.\n"; $message .= $this->returnEventText(); mail( $mailto, $subject, $message, "From: $mailfrom" ); return $this; } function updateEvent() { if( !$this->submitter_id ) {$this->error = "Your user ID got lost somewhere along the way. " ."Either your session expired or you have cookies disabled in your web browser.". " Make sure you've got cookies enabled and log in again. Then you can " ."try clicking the back button a couple times to get back to the form, so " ."you won't have to type everything in again."; return 0; } if( !$this->event_id ) { $this->submitEvent(); return; }// we'll assume that if the event has been approved, the approveEvent function// would have been called, so if there's a modify ID, it's probably an// inconsistency and we'll remove it. if( $this->approver_id && $this->modify_id ) { $this->modify_id = ""; } if (!$db_conn = connectRWToCalendar()) { $this->error = $php_errormsg; return 0; } $query = "BEGIN WORK"; if (! $result_id = @pg_exec( $db_conn, $query ) ) { $this->error = $php_errormsg . "beginning work in update."; $this->error .= " QUERY= " . $query; return 0; }// simple (or not) SQL statement to insert the event into the database// we could look for attributes that were modified and only update those,// but that would probably involve contacting the database again or// bloating the form with the old values, and in the long run would// likely be more expensive$query = "UPDATE srcevent set title = '" . $this->title . "', description = '" .$this->description . "', location_id = " . $this->location_id . ", start_time = ". $this->start_time . ", end_time = " . $this->end_time . ", submitted_time = " .$this->submitted_time . ", submitter_id = " . $this->submitter_id . ", approver_id = " .($this->approver_id ? $this->approver_id : "NULL") . ", info_url = " .($this->info_url ? "'".$this->info_url."'" : "NULL") . ", info_email = " .($this->info_email ? "'".$this->info_email."'" : "NULL") . ", hide_oc = " .($this->hide_oc ? $this->hide_oc : "NULL" ) . ", modify_id = " .($this->modify_id ? $this->modify_id : "NULL" ) ." WHERE event_id = " . $this->event_id; if (! $result_id = @pg_exec( $db_conn, $query ) ) { $this->error = $php_errormsg . "at exec in update."; $this->error .= " QUERY= " . $query; @pg_exec( $db_conn, "ROLLBACK WORK" ); return 0; }// deleting stuff and reinserting so I don't have to worry about the// new set having a different number of values $query = "DELETE from srcAudienceList WHERE event_id = " . $this->event_id; if( ! $result_id = pg_exec( $db_conn, $query ) ) { $this->error = $php_errormsg; $this->error .= " QUERY= " . $query; @pg_exec( $db_conn, "ROLLBACK WORK" ); return 0; } for( $i = 0; $i < count( $this->audience_id ); $i++ ) {$query = "INSERT INTO srcAudienceList ( event_id, audience_id ) VALUES ( ". $this->event_id . ", " . $this->audience_id[$i] . " )"; if (! $result_id = pg_exec( $db_conn, $query ) ) { $this->error = $php_errormsg . "inserting audiences"; $this->error .= " QUERY= " . $query; @pg_exec( $db_conn, "ROLLBACK WORK" ); return 0; } } $query = "DELETE from srcCategoryList WHERE event_id = " . $this->event_id; if( ! $result_id = pg_exec( $db_conn, $query ) ) { $this->error = $php_errormsg; $this->error .= " QUERY= " . $query; @pg_exec( $db_conn, "ROLLBACK WORK" ); return 0; } for( $i = 0; $i < count( $this->category_id ); $i++ ) {$query = "INSERT INTO srcCategoryList ( event_id, category_id ) VALUES ( ". $this->event_id . ", " . $this->category_id[$i] . " )"; if (! $result_id = pg_exec( $db_conn, $query ) ) { $this->error = $php_errormsg . "inserting categories"; $this->error .= " QUERY= " . $query; @pg_exec( $db_conn, "ROLLBACK WORK" ); return 0; } } $query = "DELETE from srcWeekdayList WHERE event_id = " . $this->event_id; if( ! $result_id = pg_exec( $db_conn, $query ) ) { $this->error = $php_errormsg; $this->error .= " QUERY= " . $query; @pg_exec( $db_conn, "ROLLBACK WORK" ); return 0; } for( $i = 0; $i < count( $this->weekday_id ); $i++ ) {$query = "INSERT INTO srcweekdaylist ( event_id, day ) VALUES ( ". $this->event_id . ", " . $this->weekday_id[$i] . " )"; if (! $result_id = pg_exec( $db_conn, $query ) ) { $this->error = $php_errormsg . "inserting weekdays"; $this->error .= " QUERY= " . $query; @pg_exec( $db_conn, "ROLLBACK WORK" ); return 0; } } $query = "DELETE from srcIndex WHERE event_id = " . $this->event_id; if( ! $result_id = pg_exec( $db_conn, $query ) ) { $this->error = $php_errormsg; $this->error .= " QUERY= " . $query; @pg_exec( $db_conn, "ROLLBACK WORK" ); return 0; } $timestamps = $this->generateTimestampArray(); for( $i = 0; $i < count( $timestamps ); $i++ ) {$query = "INSERT INTO srcindex ( event_id, timestamp ) VALUES ( ". $this->event_id . ", " . $timestamps[$i] . " )"; if (! $result_id = pg_exec( $db_conn, $query ) ) { $this->error = $php_errormsg . "updating index"; $this->error .= " QUERY= " . $query; @pg_exec( $db_conn, "ROLLBACK WORK" ); return 0; } } if(! $result_id = @pg_exec( $db_conn, "COMMIT WORK" ) ) { $this->error = $php_errormsg . "committing work."; $this->error .= " QUERY= " . $query; @pg_exec( $db_conn, "ROLLBACK WORK" ); return 0; } pg_close( $db_conn ); return $this->event_id; } function generateTimestampArray() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -