Exemplo n.º 1
0
 function run()
 {
     if (($e = new entity($this->admin_page->id)) && reason_is_entity($e, true)) {
         $name = 'Copy of ' . $e->get_value('name');
         if ($new_entity_id = duplicate_entity($this->admin_page->id, false, false, array('name' => $name, 'unique_name' => '', 'last_modified_by' => $this->admin_page->user_id, 'state' => 'Pending', 'new' => '1'))) {
             header('Location: ' . carl_make_redirect(array('cur_module' => 'Editor', 'id' => $new_entity_id)));
         } else {
             echo '<p>Unable to duplicate entity.</p>';
             return false;
         }
     } else {
         echo '<p>Duplicate called with invalid entity ID.</p>';
         return false;
     }
 }
Exemplo n.º 2
0
 function run()
 {
     if (reason_user_has_privs($this->admin_page->user_id, 'duplicate')) {
         echo '<h3>Cloning</h3>' . "\n";
         if (!empty($this->admin_page->request['clone']) && $this->admin_page->request['clone'] == 'true') {
             $new_entity_id = duplicate_entity($this->admin_page->id, true, false, array('last_modified_by' => $this->admin_page->user_id, 'state' => 'Pending', 'new' => '1'));
             //echo '<p>new entity successfully cloned from this entity (id #'.$new_entity_id.')<p>';
             echo '<p>Again?</p>';
         } else {
             echo '<p>This will make a duplicate of the current entity.<p>' . "\n";
             echo '<p>Note that this will not duplicate anything on the filesystem, like images, assets, site folders, etc., and that it might duplicate relationships you might not want duplicated. Use this module with care!</p>' . "\n";
             echo '<p>Do you want to do that?</p>' . "\n";
         }
         echo '<ul><li><a href="' . $this->admin_page->make_link(array('clone' => 'true')) . '">Yes</a></li><li><a href="' . $this->admin_page->make_link(array('cur_module' => 'Editor')) . '">No</a></li></ul>' . "\n";
     } else {
         echo '<p>Sorry, you do not have cloning privileges</p>' . "\n";
     }
 }
Exemplo n.º 3
0
	/**
	 * Updates entity with id = $id with the values of the array $values
	 *
	 * reason_update_entity() provides an easier-to-use interface 
	 * where the updates do not need to be organized by table.
	 *
	 * @todo figure out how to refresh the entity data cache on update
	 *
	 * @param integer $id ID of entity to update
	 * @param integer $user_id Reason ID of user making changes
	 * @param array $updates array of tables with values being array of key-val pairs
	 * @param boolean $archive boolean that determines whether this update will be archived
	 * @return boolean true => entity has changed,  false => entity has not changed
	 */
	function update_entity( $id, $user_id, $raw_updates = array(), $archive = true )
	{
		$original = new entity($id, false);
		if (reason_is_entity($original, true)) // must be an entity of some type.
		{
			if (isset($raw_updates['entity']['type']) && ($raw_updates['entity']['type'] != $original->get_value('type')))
			{
				trigger_error('update_entity cannot be used to change the type of an entity.');
			}
			foreach( $raw_updates AS $table => $raw_fields )
			{
				$updates[$table] = reason_sanitize_values($original->get_value('type'), $raw_fields);
				if (empty($changed))
				{
					foreach ($updates[$table] as $k => $v) // see if this represents a change.
					{
						if ($v != $original->get_value($k))
						{
							$changed = true;
							break;
						}
					}
				}
			}
			if (!empty($changed)) // some change took place
			{
				if (!isset($updates['entity']['last_edited_by'])) $updates['entity']['last_edited_by'] = $user_id;
				if (!isset($updates['entity']['last_modified'])) $updates['entity']['last_modified'] = get_mysql_datetime();
				foreach  ($updates as $table => $fields)
				{
					$GLOBALS['sqler']->update_one( $table, $fields, $id );
				}
				if (!empty($archive))
				{
					$archived_id = duplicate_entity( $original, false, true, array( 'state' => 'Archived' ) );
					$rel_id = reason_get_archive_relationship_id($original->get_value('type'));
					create_relationship( $id, $archived_id, $rel_id );
				}
				$updated_entity = new entity($id, false);
				$updated_entity->get_values();
				// If the unique_name changes on the updated entity, or a uniquely named entity is deleted or undeleted, lets update the unique name cache
				if ($updated_entity->get_value('unique_name') != $original->get_value('unique_name') ||
					($original->get_value('state') != 'Deleted' && $updated_entity->get_value('state') == 'Deleted' && $original->get_value('unique_name')) ||
					($original->get_value('state') == 'Deleted' && $updated_entity->get_value('state') != 'Deleted' && $updated_entity->get_value('unique_name')))
				{
					reason_refresh_unique_names();
				}
				return true;
			}
		}
		else
		{
			trigger_error('update_entity requires a valid entity id (was given ' . $id . ').');
		}
		return false;
	}
Exemplo n.º 4
0
/**
 * Split a repeating event into separate entities
 *
 * If event is not repeating, nothing will happen and the returned array will contain just the 
 * existing event's ID.
 *
 * @param object $event entity
 * @param integer $user_id
 * @return array updated/created IDs
 *
 * @todo determine a way to integrate with Carleton event calendar
 */
function reason_split_event($event, $user_id)
{
    $user_id = (int) $user_id;
    if (empty($user_id)) {
        trigger_error('User ID required to split an event');
        return array();
    }
    $ret = array($event->id());
    $dates = explode(', ', $event->get_value('dates'));
    sort($dates);
    if (count($dates) > 1) {
        $i = 1;
        foreach ($dates as $date) {
            $overrides = array('datetime' => $date . ' ' . substr($event->get_value('datetime'), 11), 'dates' => $date, 'recurrence' => 'none', 'last_occurence' => $date, 'frequency' => '', 'week_of_month' => '', 'month_day_of_week' => '', 'monthly_repeat' => '');
            if ($i < 2) {
                reason_update_entity($event->id(), $user_id, $overrides);
            } else {
                $overrides['unique_name'] = '';
                $overrides['last_modified'] = date('Y-m-d h:i:s');
                $overrides['last_edited_by'] = $user_id;
                $overrides['creation_date'] = date('Y-m-d h:i:s');
                $overrides['created_by'] = $user_id;
                $ret[] = duplicate_entity($event->id(), true, false, $overrides);
            }
            $i++;
        }
    }
    return $ret;
}
Exemplo n.º 5
0
 function init()
 {
     if (!$this->admin_page->id) {
         return false;
     }
     //these next few lines check the entity to make sure it has everything it needs
     $this->load_content_manager();
     $this->check_entity_values();
     $this->get_required_relationships();
     if (!empty($this->req_rels)) {
         $this->check_required_relationships();
     }
     /* the new finish stuff */
     // new_entity stuff
     // figure out if the entity is new and store that so we can change the data in the database but still know what's going on
     $temp = new entity($this->admin_page->id, false);
     if ($temp->get_value('new')) {
         $this->new_entity = true;
     } else {
         $this->new_entity = false;
     }
     // when finishing an entity, we want to ensure that it is live and not new (unless it is a page)
     if ($this->admin_page->type_id != id_of('minisite_page') && $temp->get_value('state') == 'Pending' && reason_user_has_privs($this->admin_page->user_id, 'publish')) {
         $update_values['state'] = 'Live';
         if (!empty($this->disco_item)) {
             $this->disco_item->set_value('state', "Live");
         }
     }
     if ($temp->get_value('new') != '0') {
         $update_values['new'] = 0;
         if (!empty($this->disco_item)) {
             $this->disco_item->set_value('new_entity', 0);
         }
     }
     if (!empty($update_values)) {
         reason_update_entity($this->admin_page->id, $this->admin_page->user_id, $update_values, false);
         // archive, yes?
     }
     $original = new entity($this->admin_page->id, false);
     $original->get_values();
     // get archive relationship id
     $q = 'SELECT id FROM allowable_relationship WHERE name LIKE "%archive%" AND relationship_a = ' . $this->admin_page->type_id . ' AND relationship_b = ' . $this->admin_page->type_id;
     $r = db_query($q, 'Unable to get archive relationship.');
     $row = mysql_fetch_array($r, MYSQL_ASSOC);
     $this->rel_id = $row['id'];
     // get archives
     $es = new entity_selector($this->admin_page->site_id);
     $es->add_type($this->admin_page->type_id);
     $es->add_right_relationship($this->admin_page->id, $this->rel_id);
     $es->add_relation('last_modified = "' . $original->get_value('last_modified') . '"');
     $es->set_num(1);
     $similar_archived = $es->run_one('', 'Archived');
     // if the entity has in fact been changed, actually create the relationship
     if (empty($similar_archived)) {
         $archived_id = duplicate_entity($original, false, true, array('state' => 'Archived'));
         create_relationship($this->admin_page->id, $archived_id, $this->rel_id);
     }
     // DETERMINE WHERE TO GO
     if (!empty($this->admin_page->request[CM_VAR_PREFIX . 'type_id'])) {
         // this code block is intended to associate a new entity with the context entity upon finish - it once created backwards relationships IF we reached an
         // entity with get_value('new') = 1 from the reverse associator. This needs fixin. We do so by running this section of code only in the case where
         // the "old" module was the associator (the only module that allows the creation of new entities than need a relationship back to the a side entity
         // whose context is relevant.
         if ($this->new_entity && $this->admin_page->request[CM_VAR_PREFIX . 'cur_module'] == 'Associator') {
             $rel_info = reason_get_allowable_relationship_info($this->admin_page->request[CM_VAR_PREFIX . 'rel_id']);
             $entity_a = new entity($this->admin_page->request[CM_VAR_PREFIX . 'id']);
             $entity_b = new entity($this->admin_page->request['id']);
             // lets do a bit of additional sanity checking.
             if ($rel_info['relationship_a'] == $entity_a->get_value('type') && $rel_info['relationship_b'] == $entity_b->get_value('type')) {
                 if ($rel_info['connections'] == 'one_to_many') {
                     $this->delete_existing_relationships();
                 }
                 create_relationship($entity_a->id(), $entity_b->id(), $rel_info['id']);
             }
         }
         $old_vars = array();
         foreach ($this->admin_page->request as $key => $val) {
             if (substr($key, 0, strlen(CM_VAR_PREFIX)) == CM_VAR_PREFIX) {
                 $old_vars[substr($key, strlen(CM_VAR_PREFIX))] = $val;
                 $old_vars[$key] = '';
             }
         }
         foreach ($this->admin_page->default_args as $arg) {
             if (!isset($old_vars[$arg])) {
                 $old_vars[$arg] = '';
             }
         }
         $link = $this->admin_page->make_link($old_vars);
     } elseif (!empty($this->admin_page->request['next_entity'])) {
         $link = $this->admin_page->make_link(array('cur_module' => 'Editor', 'id' => $this->admin_page->request['next_entity']));
     } else {
         $link = $this->admin_page->make_link(array('id' => '', 'site_id' => $this->admin_page->site_id, 'type_id' => $this->admin_page->type_id, 'cur_module' => 'Lister'));
     }
     // before redirecting, check to see if there are any custom finish actions associated with this type.
     // the entity_type variable is declared earlier in the check_entity_values method.
     //Run any custom finish actions specified in the content manager
     if (!empty($this->disco_item)) {
         $this->disco_item->run_custom_finish_actions($this->new_entity);
     }
     if ($this->entity_type->get_value('finish_actions')) {
         $finish_actions_filename = $this->entity_type->get_value('finish_actions');
     } else {
         $finish_actions_filename = 'default.php';
     }
     reason_include_once('finish_actions/' . $finish_actions_filename);
     $finish_action_class_name = $GLOBALS['_finish_action_classes'][$finish_actions_filename];
     $fac = new $finish_action_class_name();
     $vars = array('site_id' => $this->admin_page->site_id, 'type_id' => $this->admin_page->type_id, 'id' => $this->admin_page->id, 'user_id' => $this->admin_page->user_id);
     $fac->init($vars);
     $fac->run();
     header('Location: ' . unhtmlentities($link));
     die;
 }