Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fd3f026
Showing
8 changed files
with
285 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
class ColorField extends TextField { | ||
|
||
function __construct($name, $title = null, $value = '#000000') { | ||
parent::__construct($name, $title, $value); | ||
//Requirements::javascript('getsmart/javascript/jquery/jquery-1.3.2.min.js'); | ||
Requirements::javascript('getsmart/javascript/jquery/farbtastic.js'); | ||
Requirements::javascript('getsmart/javascript/jquery/colorfield.js'); | ||
Requirements::css('getsmart/css/ColorField.css'); | ||
Requirements::css('getsmart/css/farbtastic.css');//echo $this->value; | ||
} | ||
|
||
function Field() { | ||
$field = parent::Field(); | ||
$field .= '<img src="getsmart/images/colorfield/color-icon.png" class="coloricon"/><div class="colorpopup"></div>'; | ||
return $field; | ||
} | ||
} | ||
|
||
class ColorField_ReadOnly extends ReadonlyField { | ||
|
||
function Field() { | ||
if($this->value) $value = $this->dontEscape ? ($this->reserveNL ? Convert::raw2xml($this->value) : $this->value) : Convert::raw2xml($this->value); | ||
else $value = '<i>(' . _t('FormField.NONE', 'none') . ')</i>'; | ||
|
||
$attributes = array( | ||
'id' => $this->id(), | ||
'class' => 'readonly' . ($this->extraClass() ? $this->extraClass() : '') | ||
); | ||
if($this->value) $attributes['style'] = "background-color: $this->value"; | ||
|
||
$hiddenAttributes = array( | ||
'type' => 'hidden', | ||
'name' => $this->name, | ||
'value' => $this->value, | ||
'tabindex' => $this->getTabIndex() | ||
); | ||
|
||
$containerSpan = $this->createTag('span', $attributes, $value); | ||
$hiddenInput = $this->createTag('input', $hiddenAttributes); | ||
|
||
return $containerSpan . "\n" . $hiddenInput; | ||
} | ||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
/** | ||
* CreditCard field, contains validation and formspec for creditcard fields. | ||
* @package forms | ||
* @subpackage fields-formattedinput | ||
*/ | ||
class DOBField extends CalendarDateField { | ||
|
||
protected $minimumAgeInYears = 5; | ||
|
||
protected $maximumAgeInYears = 150; | ||
|
||
protected static $date_not_valid_error = "Please enter a valid date of birth (DD-MM-YYYY, e.g. 01-10-1921)."; | ||
static function set_date_not_valid_error ($v) {self::$date_not_valid_error = $v;} | ||
|
||
protected static $too_young_error = "Sorry, you are too young."; | ||
static function set_too_young_error ($v) {self::$too_young_error = $v;} | ||
|
||
protected static $too_old_error = "Sorry, you are too old"; | ||
static function set_too_old_error ($v) {self::$too_old_error = $v;} | ||
|
||
function setValue( $value ) { | ||
if( is_array( $value ) && $value['Day'] && $value['Month'] && $value['Year'] ) | ||
$this->value = $value['Year'] . '-' . $value['Month'] . '-' . $value['Day']; | ||
else if(is_array($value)&&(!$value['Day']||!$value['Month']||!$value['Year'])) | ||
$this->value = null; | ||
else if(is_string($value)) | ||
$this->value = $value; | ||
} | ||
|
||
function Field() { | ||
$val = $this->attrValue(); | ||
if( preg_match( '/^\d{2}\/\d{2}\/\d{4}$/', $val ) ) { | ||
$dateArray = explode( '/', $val ); | ||
$val = $dateArray[2] . '-' . $dateArray[1] . '-' . $dateArray[0]; | ||
} | ||
$day = $month = $year = null; | ||
if($val) { | ||
$dateArray = explode( '-', $val ); | ||
$day = $dateArray[2]; | ||
$month = $dateArray[1]; | ||
$year = $dateArray[0]; | ||
} | ||
$id = $this->name; | ||
$fieldName = $this->name; | ||
$tabIndex0 = $this->getTabIndexHTML(0); | ||
$tabIndex1 = $this->getTabIndexHTML(1); | ||
$tabIndex2 = $this->getTabIndexHTML(2); | ||
|
||
Requirements::javascript("formextensions/javascript/DOBField.js"); | ||
return <<<HTML | ||
<div class="dobfield"> | ||
<span class="littleDOBLabel">day: </span><input type="text" id="$id-day" class="day numeric" name="{$fieldName}[Day]" value="$day" maxlength="2"$tabIndex0 /> | ||
<span class="littleDOBLabel"> month: </span><input type="text" id="$id-month" class="month numeric" name="{$fieldName}[Month]" value="$month" maxlength="2"$tabIndex1 /> | ||
<span class="littleDOBLabel"> year: </span><input type="text" id="$id-year" class="year numeric" name="{$fieldName}[Year]" value="$year" maxlength="4"$tabIndex2 /> | ||
</div> | ||
HTML; | ||
} | ||
|
||
function validate($validator){ | ||
$errorDescription = ''; | ||
$userDate = strtotime($this->value); | ||
if(!empty ($this->value) && (!preg_match('/^[0-90-9]{2,4}\-[0-9]{1,2}\-[0-90-9]{1,2}$/', $this->value) || !$userDate ) ) { | ||
$errorDescription = self::$date_not_valid_error; | ||
} | ||
else { | ||
if($this->minimumAgeInYears) { | ||
$minimumDate = strtotime("-".$this->minimumAgeInYears." Years"); | ||
if($minimumDate < $userDate) { | ||
$errorDescription = self::$too_young_error; | ||
} | ||
} | ||
if($this->maximumAgeInYears) { | ||
$maximumDate = strtotime("-".$this->maximumAgeInYears." Years"); | ||
if($maximumDate > $userDate) { | ||
$errorDescription = self::$too_old_error; | ||
} | ||
} | ||
|
||
} | ||
if($errorDescription) { | ||
$validator->validationError( | ||
$this->name, | ||
$errorDescription, | ||
"validation", | ||
false | ||
); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
function setMinimumAge($v) { | ||
$this->minimumAgeInYears = $v; | ||
} | ||
|
||
function setMaximumAge($v) { | ||
$this->maximumAgeInYears = $v; | ||
} | ||
|
||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
class DayField extends DropdownField { | ||
|
||
function __construct($name, $title = null, $value = '') { | ||
for($i = 1; $i <= 31; $i++) $days[$i] = date('jS', mktime(0, 0, 0, 1, $i, 2008)); | ||
parent::__construct($name, $title, $days, $value); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
class DropdownOtherField extends DropdownField { | ||
|
||
static $field = 'DropdownField'; | ||
|
||
static $dropdownIndex = 'Value'; | ||
static $textareaIndex = 'Other'; | ||
|
||
protected $dropdownName; | ||
protected $textareaName; | ||
|
||
protected $other; | ||
|
||
function __construct($name, $title, $source, $value, $other, $otherFieldText) { | ||
$source[self::$textareaIndex] = $otherFieldText ? $otherFieldText : 'Other (Please Enter Below)'; | ||
if(! $value && $other != null) $value = self::$textareaIndex; | ||
parent::__construct($name, $title, $source, $value); | ||
$this->dropdownName = $this->name . '[' . self::$dropdownIndex . ']'; | ||
$this->textareaName = $this->name . '[' . self::$textareaIndex . ']'; | ||
$this->other = $other; | ||
Requirements::javascript('survey/javascript/jquery/jquery-1.3.2.js'); | ||
Requirements::javascript('survey/javascript/otherfield.js'); | ||
} | ||
|
||
function Field() { | ||
$field = $this->stat('field'); | ||
$dropdown = new $field($this->dropdownName, $this->title, $this->source, $this->value); | ||
$dropdownField = $dropdown->Field(); | ||
$textarea = new TextareaField($this->textareaName, null, 5, 20, $this->other); | ||
$textareaField = $textarea->Field(); | ||
return $dropdownField . $textareaField; | ||
} | ||
|
||
function setValue($val) { | ||
if(is_array($val)) { // Comes From The Form | ||
$this->value = $val[self::$dropdownIndex] == self::$textareaIndex ? null : $val[self::$dropdownIndex]; | ||
$this->other = $val[self::$dropdownIndex] == self::$textareaIndex ? $val[self::$textareaIndex] : null; | ||
} | ||
else $this->value = $val; | ||
return $this; | ||
} | ||
|
||
function saveInto(SurveyAnswer $answer) { | ||
$answer->setCastedField('Answer', $this->dataValue()); | ||
$answer->setCastedField('Other', $this->other); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
class FontField extends DropdownField { | ||
|
||
static $font_families = array( | ||
'Arial', | ||
'Courier', | ||
'Courier New', | ||
'Georgia', | ||
'Lucida Console', | ||
'Times', | ||
'Times New Roman', | ||
'Verdana' | ||
); | ||
|
||
static $generic_families = array( | ||
'Cursive', | ||
'Fantasy', | ||
'Monospace', | ||
'Sans-serif', | ||
'Serif' | ||
); | ||
|
||
function __construct($name, $title = null, $value = '') { | ||
foreach(self::$font_families as $fontFamily) { | ||
foreach(self::$generic_families as $genericFamily) { | ||
$font = (strpos($fontFamily, ' ') ? "'$fontFamily'" : $fontFamily) . ", $genericFamily"; | ||
$fonts[strtolower($font)] = $font; | ||
} | ||
} | ||
parent::__construct($name, $title, $fonts, $value); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
class MonthField extends DropdownField { | ||
|
||
function __construct($name, $title = null, $value = '') { | ||
for($i = 1; $i <= 12; $i++) $months[$i] = $i; | ||
parent::__construct($name, $title, $months, $value); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
class OptionsetOtherField extends DropdownOtherField { | ||
|
||
static $field = 'OptionsetField'; | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
class RatingField extends OptionsetField { | ||
|
||
function __construct($name, $title = "", $source = array(), $value = "", $form = null) { | ||
parent::__construct($name, $title, $source, $value, $form); | ||
Requirements::javascript('survey/javascript/jquery/jquery-1.3.2.js'); | ||
Requirements::javascript('survey/javascript/jquery/ui.core.js'); | ||
Requirements::javascript('survey/javascript/jquery/ui.slider.js'); | ||
Requirements::javascript('survey/javascript/ratingfield.js'); | ||
Requirements::css('survey/css/ui.core.css'); | ||
Requirements::css('survey/css/ui.slider.css'); | ||
Requirements::css('survey/css/ui.theme.css'); | ||
} | ||
|
||
} | ||
|
||
?> |