예제 #1
0
function render_add_reminders_config($reminder_opt) {
	$defaults = array();
	$def = explode(",", user_config_option($reminder_opt));
	$default_defaults = array(
		'type' => array_var($def, 0),
		'duration' => array_var($def, 1),
		'duration_type' => array_var($def, 2)
	);

	foreach ($default_defaults as $k => $v) {
		if (!isset($defaults[$k])) $defaults[$k] = $v;
	}
	$types = ObjectReminderTypes::findAll();
	$typecsv = array();
	foreach ($types as $type) {
		$typecsv []= $type->getName();
	}
	$durations = array(0,1,2,5,10,15,30);
	$duration_types = array("1" => "minutes","60" => "hours","1440" => "days","10080" => "weeks");

	$output = '<select name="options['.$reminder_opt.'][reminder_type]">';
	foreach ($typecsv as $type) {
		$output .= '<option value="' . $type . '"';
		if ($type == array_var($defaults, 'type')) {
			$output .= ' selected="selected"';
		}
		$output .= '>' . lang($type) . '</option>';
	}
	$output .= '</select>';

	$output .= '<select name="options['.$reminder_opt.'][reminder_duration]">';
	foreach ($durations as $duration) {
		$output .= '<option value="' . $duration . '"';
		if ($duration == array_var($defaults, 'duration')) {
			$output .= ' selected="selected"';
		}
		$output .= '>' . $duration . '</option>';
	}
	$output .= '</select>';

	$output .= '<select name="options['.$reminder_opt.'][reminder_duration_type]">';
	foreach ($duration_types as $key => $value) {
		$output .= '<option value="' . $key . '"';
		if ($key == array_var($defaults, 'duration_type')) {
			$output .= ' selected="selected"';
		}
		$output .= '>' . lang($value) . '</option>';
	}
	$output .= '</select>';
	
	return $output;
}
예제 #2
0
function render_add_reminders($object, $context, $defaults = null, $genid = null)
{
    require_javascript('og/Reminders.js');
    if (!is_array($defaults)) {
        $defaults = array();
    }
    $default_defaults = array('type' => 'reminder_popup', 'duration' => '15', 'duration_type' => '1', 'for_subscribers' => true);
    foreach ($default_defaults as $k => $v) {
        if (!isset($defaults[$k])) {
            $defaults[$k] = $v;
        }
    }
    if (is_null($genid)) {
        $genid = gen_id();
    }
    $types = ObjectReminderTypes::findAll();
    $typecsv = "";
    foreach ($types as $type) {
        if ($typecsv != "") {
            $typecsv .= ",";
        }
        $typecsv .= '"' . $type->getName() . '"';
    }
    $output = '
		<div id="' . $genid . '" class="og-add-reminders">
			<a id="' . $genid . '-link" href="#" onclick="og.addReminder(this.parentNode, \'' . $context . '\', \'' . $defaults['type'] . '\', \'' . $defaults['duration'] . '\', \'' . $defaults['duration_type'] . '\', \'' . $defaults['for_subscribers'] . '\', this);return false;">' . lang("add object reminder") . '</a>
		</div>
		<script>
		og.reminderTypes = [' . $typecsv . '];
		</script>
	';
    if ($object->isNew()) {
        $output .= '<script>og.addReminder(document.getElementById("' . $genid . '"), \'' . $context . '\', \'' . $defaults['type'] . '\', \'' . $defaults['duration'] . '\', \'' . $defaults['duration_type'] . '\', \'' . $defaults['for_subscribers'] . '\', document.getElementById("' . $genid . '-link"));</script>';
    } else {
        $reminders = ObjectReminders::getAllRemindersByObjectAndUser($object, logged_user(), $context, true);
        foreach ($reminders as $reminder) {
            $mins = $reminder->getMinutesBefore();
            if ($mins % 10080 == 0) {
                $duration = $mins / 10080;
                $duration_type = "10080";
            } else {
                if ($mins % 1440 == 0) {
                    $duration = $mins / 1440;
                    $duration_type = "1440";
                } else {
                    if ($mins % 60 == 0) {
                        $duration = $mins / 60;
                        $duration_type = "60";
                    } else {
                        $duration = $mins;
                        $duration_type = "1";
                    }
                }
            }
            $type = $reminder->getType();
            $forSubscribers = $reminder->getUserId() == 0 ? "true" : "false";
            $output .= '<script>og.addReminder(document.getElementById("' . $genid . '"), "' . $context . '", "' . $type . '", "' . $duration . '", "' . $duration_type . '", ' . $forSubscribers . ', document.getElementById(\'' . $genid . '-link\'));</script>';
        }
        // for
    }
    return $output;
}