public function updateCMSFields(FieldSet $fields)
 {
     $fields->replaceField('TrackedLinks', $tracked = new TableListField('LinkViews', 'NewsletterLinkView', null, '"NewsletterID" = ' . $this->owner->ID, '"Created" DESC'));
     $tracked->setPermissions(array('show', 'export'));
     $viewers = new TableListField('Views', 'NewsletterView', null, '"NewsletterID" = ' . $this->owner->ID, '"Created" DESC');
     $viewers->setPermissions(array('show', 'export'));
     $fields->addFieldsToTab('Root.ViewedBy', array(new LiteralField('ViewsNote', '<p>The viewed by list may not be ' . 'accurate, as many email clients block images used for ' . 'tracking by default.</p>'), $viewers));
 }
 function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $tf = new TableListField('CompaniesTF', 'Company');
     $tf->setShowPagination(true);
     $ctf = new ComplexTableField($this, 'CompaniesCTF', 'Company');
     $fields->addFieldsToTab('Root.Fields', array($tf, $ctf));
     return $fields;
 }
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $categories = new TableListField('Categories', false, array('Label' => 'Label', 'Term' => 'Term', 'Scheme' => 'Scheme'));
     $categories->setCustomSourceItems($this->categories);
     $fields->addFieldsToTab('Root.Details', array(new HeaderField('CategoriesHeader', 'Categories', 4), $categories->performReadonlyTransformation()));
     $fields->addFieldsToTab('Root.Location', array(new ReadonlyField('Latitude', null, $this->Latitude), new ReadonlyField('Longitude', null, $this->Longitude)));
     $fields->addFieldToTab('Root.Behaviour', new ReadonlyField('ShowInMenus', null, $this->ShowInMenus));
     return $fields;
 }
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->removeByName('Tickets');
     $fields->removeByName('Total');
     $fields->removeByName('Token');
     $fields->removeByName('TimeID');
     $fields->addFieldToTab('Root.Tickets', $tickets = new TableListField('Tickets', 'EventTicket', array('Title' => 'Ticket Title', 'PriceSummary' => 'Price', 'Quantity' => 'Quantity')));
     $tickets->setCustomSourceItems($this->Tickets());
     if (class_exists('Payment')) {
         $fields->addFieldToTab('Root.Tickets', new ReadonlyField('TotalNice', 'Total', $this->Total->Nice()));
     }
     return $fields;
 }
 /**
  * Returns a FieldSet with which to create the CMS editing form.
  * You can use the extend() method of FieldSet to create customised forms for your other
  * data objects.
  *
  * @param Controller
  * @return FieldSet
  */
 function getCMSFields($controller = null)
 {
     $group = DataObject::get_by_id("Group", $this->Parent()->GroupID);
     $sentReport = $this->renderWith("Newsletter_SentStatusReport");
     $previewLink = Director::absoluteBaseURL() . 'admin/newsletter/preview/' . $this->ID;
     $ret = new FieldSet(new TabSet("Root", $mailTab = new Tab(_t('Newsletter.NEWSLETTER', 'Newsletter'), new TextField("Subject", _t('Newsletter.SUBJECT', 'Subject'), $this->Subject), new HtmlEditorField("Content", _t('Newsletter.CONTENT', 'Content')), new LiteralField('PreviewNewsletter', "<p><a href=\"{$previewLink}\" target=\"_blank\">" . _t('PREVIEWNEWSLETTER', 'Preview this newsletter') . "</a></p>")), $sentToTab = new Tab(_t('Newsletter.SENTREPORT', 'Sent Status Report'), new LiteralField("SentStatusReport", $sentReport)), $tracked = new Tab('TrackedLinks', $trackedTable = new TableListField('TrackedLinks', 'Newsletter_TrackedLink', array('Original' => 'Link', 'Visits' => 'Visits'), '"NewsletterID" = ' . $this->ID, '"Visits" DESC'))));
     $tracked->setTitle(_t('Newsletter.TRACKEDLINKS', 'Tracked Links'));
     $trackedTable->setPermissions(array('show'));
     if ($this->Status != 'Draft') {
         $mailTab->push(new ReadonlyField("SentDate", _t('Newsletter.SENTAT', 'Sent at'), $this->SentDate));
     }
     $this->extend("updateCMSFields", $ret);
     return $ret;
 }
Exemple #6
0
 protected function formatValue($record, $source, $info)
 {
     // Field sources
     //if(is_string($source)) {
     $val = Convert::raw2xml($record->{$source});
     //} else {
     //	$val = $record->val($source[0], $source[1]);
     //}
     // Casting, a la TableListField.  We're deep-calling a helper method on TableListField that
     // should probably be pushed elsewhere...
     if (!empty($info['casting'])) {
         $val = TableListField::getCastedValue($val, $info['casting']);
     }
     // Formatting, a la TableListField
     if (!empty($info['formatting'])) {
         $format = str_replace('$value', "__VAL__", $info['formatting']);
         $format = preg_replace('/\\$([A-Za-z0-9-_]+)/', '$record->$1', $format);
         $format = str_replace('__VAL__', '$val', $format);
         $val = eval('return "' . $format . '";');
     }
     $prefix = empty($info['newline']) ? "" : "<br>";
     $classClause = "";
     if (isset($info['title'])) {
         $cssClass = preg_replace('/[^A-Za-z0-9]+/', '', $info['title']);
         $classClause = "class=\"{$cssClass}\"";
     }
     if (isset($info['link']) && $info['link']) {
         $link = $info['link'] === true && $record->hasMethod('CMSEditLink') ? $record->CMSEditLink() : $info['link'];
         return $prefix . "<a {$classClause} href=\"{$link}\">{$val}</a>";
     } else {
         return $prefix . "<span {$classClause}>{$val}</span>";
     }
 }
Exemple #7
0
 function __construct($name, $sourceClass, $fieldList, $fieldTypes, $filterField = null, $sourceFilter = null, $editExisting = true, $sourceSort = null, $sourceJoin = null)
 {
     $this->fieldTypes = $fieldTypes;
     $this->filterField = $filterField;
     $this->editExisting = $editExisting;
     parent::__construct($name, $sourceClass, $fieldList, $sourceFilter, $sourceSort, $sourceJoin);
     Requirements::javascript('sapphire/javascript/TableField.js');
 }
 function getQuery()
 {
     $oldState = Subsite::$disable_subsite_filter;
     Subsite::$disable_subsite_filter = true;
     $return = parent::getQuery();
     Subsite::$disable_subsite_filter = $oldState;
     return $return;
 }
 function Items()
 {
     if (class_exists('Subsite')) {
         Subsite::$disable_subsite_filter = true;
     }
     $items = parent::Items();
     if (class_exists('Subsite')) {
         Subsite::$disable_subsite_filter = false;
     }
     return $items;
 }
 function testCsvExport()
 {
     $table = new TableListField("Tester", "TableListFieldTest_CsvExport", array("A" => "Col A", "B" => "Col B"));
     $form = new Form(new TableListFieldTest_TestController(), "TestForm", new FieldSet($table), new FieldSet());
     $csvResponse = $table->export();
     $csvOutput = $csvResponse->getBody();
     $this->assertNotEquals($csvOutput, false);
     // Create a temporary file and write the CSV to it.
     $csvFileName = tempnam(TEMP_FOLDER, 'csv-export');
     $csvFile = fopen($csvFileName, 'w');
     fwrite($csvFile, $csvOutput);
     fclose($csvFile);
     $csvFile = fopen($csvFileName, 'r');
     $csvRow = fgetcsv($csvFile);
     $this->assertEquals($csvRow, array('Col A', 'Col B'));
     $csvRow = fgetcsv($csvFile);
     $this->assertEquals($csvRow, array('"A field, with a comma"', 'A second field'));
     fclose($csvFile);
     unlink($csvFileName);
 }
 public function updateEditForm(Form $form)
 {
     if (($record = $form->getRecord()) instanceof SiteTree) {
         if (!$record->numChildren()) {
             return;
         }
     }
     Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
     Requirements::javascript('siteexporter/javascript/SiteExportAdmin.js');
     $action = new FormAction('doExport');
     $action->useButtonTag = true;
     $action->setButtonContent('Export');
     $exports = new TableListField('SiteExports', 'SiteExport', null, sprintf('"ParentClass" = \'%s\' AND "ParentID" =  %d', ClassInfo::baseDataClass($form->getRecord()->class), $form->getRecord()->ID));
     $exports->setFieldFormatting(array('Archive.Name' => '<a href=\\"{$Archive()->Link()}\\">{$Archive()->Name}</a>'));
     $exports->setForm($form);
     $fields = array(new HeaderField('ExportSiteHeader', 'Export Site As Zip'), new OptionSetField('ExportSiteBaseUrlType', 'Base URL type', array('fixed' => 'Set the site base URL to a fixed value', 'rewrite' => 'Attempt to rewrite URLs to be relative'), 'fixed'), new TextField('ExportSiteBaseUrl', 'Base URL', Director::absoluteBaseURL()), new DropdownField('ExportSiteTheme', 'Theme', SiteConfig::current_site_config()->getAvailableThemes(), null, null, '(Use default theme)'), $action, new HeaderField('SiteExportsHeader', 'Site Exports'), $exports);
     $form->Fields()->addFieldsToTab('Root.Export', $fields);
     if (class_exists('QueuedJobService')) {
         $form->Fields()->addFieldToTab('Root.Export', new LiteralField('ExporSiteQueuedNote', '<p>The site export' . ' will not be performed immediately, but will be ' . ' processed in the background as a queued job. You can' . ' enter an email address below to send a notification' . ' email to when the job is complete:</p>'), 'action_doExport');
         $email = new EmailField('ExportSiteCompleteEmail', 'Notification email address');
         $email->setForm($form);
         $form->Fields()->addFieldToTab('Root.Export', $email, 'action_doExport');
     }
 }
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     if ($this->ID) {
         // now swap out to an orderable CTF field
         $fields->removeFieldFromTab('Root.Items', 'Items');
         foreach ($this->has_many() as $relationship => $component) {
             $relationshipFields = singleton($component)->summaryFields();
             $foreignKey = $this->getRemoteJoinField($relationship);
             $ctf = new DataListOrderableComplexTableField($this, $relationship, $component, $relationshipFields, "getCMSFields", "\"{$foreignKey}\" = " . $this->ID);
             $ctf->setPermissions(TableListField::permissions_for_object($component));
             $fields->addFieldToTab('Root.Items', $ctf);
         }
     }
     return $fields;
 }
 /**
  * Return a {@link ComplexTableField} that shows
  * all Order instances that are current.
  *
  * "Current" means all Orders that don't have a
  * Status property of "Complete" or "Cancelled".
  *
  * @return ComplexTableField
  */
 function getReportField()
 {
     // Get the fields used for the table columns
     $fields = Order::$table_overview_fields;
     // Add some fields specific to this report
     $fields['Invoice'] = '';
     $fields['Print'] = '';
     $table = new TableListField('Orders', 'Order', $fields);
     // Customise the SQL query for Order, because we don't want it querying
     // all the fields. Invoice and Printed are dummy fields that just have some
     // text in them, which would be automatically queried if we didn't specify
     // a custom query.
     $query = singleton('Order')->buildSQL("\"Order\".\"Status\" NOT IN ('Complete', 'Cancelled')", '"Order"."Created" DESC');
     $query->groupby[] = '"Order"."Created"';
     $table->setCustomQuery($query);
     // Set the links to the Invoice and Print fields allowing a user to view
     // another template for viewing an Order instance
     $table->setFieldFormatting(array('Invoice' => '<a href=\\"OrderReport_Popup/invoice/$ID\\">Invoice</a>', 'Print' => '<a target=\\"_blank\\" href=\\"OrderReport_Popup/index/$ID?print=1\\">Print</a>'));
     $table->setFieldCasting(array('Created' => 'Date', 'Total' => 'Currency->Nice'));
     $table->setPermissions(array('edit', 'show', 'export', 'delete'));
     return $table;
 }
 function TestForm()
 {
     $table = new TableListField("Table", "TableListFieldTest_Obj", array("A" => "Col A", "B" => "Col B", "C" => "Col C", "D" => "Col D", "E" => "Col E"));
     $table->disableSorting();
     // A TableListField must be inside a form for its links to be generated
     return new Form($this, "TestForm", new FieldSet($table), new FieldSet());
 }
 /**
  * Legacy: Please use permissions instead
  */
 function isReadonly()
 {
     return $this->parent->Can('delete');
 }
	/**
	 * Gets the form fields as defined through the metadata
	 * on {@link $obj} and the custom parameters passed to FormScaffolder.
	 * Depending on those parameters, the fields can be used in ajax-context,
	 * contain {@link TabSet}s etc.
	 * 
	 * @return FieldSet
	 */
	public function getFieldSet() {
		$fields = new FieldSet();
		
		// tabbed or untabbed
		if($this->tabbed) {
			$fields->push(new TabSet("Root", $mainTab = new Tab("Main")));
			$mainTab->setTitle(_t('SiteTree.TABMAIN', "Main"));
		}
		
		// add database fields
		foreach($this->obj->db() as $fieldName => $fieldType) {
			if($this->restrictFields && !in_array($fieldName, $this->restrictFields)) continue;
			
			// @todo Pass localized title
			if($this->fieldClasses && isset($this->fieldClasses[$fieldName])) {
				$fieldClass = $this->fieldClasses[$fieldName];
				$fieldObject = new $fieldClass($fieldName);
			} else {
				$fieldObject = $this->obj->dbObject($fieldName)->scaffoldFormField(null, $this->getParamsArray());
			}
			$fieldObject->setTitle($this->obj->fieldLabel($fieldName));
			if($this->tabbed) {
				$fields->addFieldToTab("Root.Main", $fieldObject);
			} else {
				$fields->push($fieldObject);
			}
		}
		
		// add has_one relation fields
		if($this->obj->has_one()) {
			foreach($this->obj->has_one() as $relationship => $component) {
				if($this->restrictFields && !in_array($relationship, $this->restrictFields)) continue;
				$hasOneField = $this->obj->dbObject("{$relationship}ID")->scaffoldFormField(null, $this->getParamsArray());
				$hasOneField->setTitle($this->obj->fieldLabel($relationship));
				if($this->tabbed) {
					$fields->addFieldToTab("Root.Main", $hasOneField);
				} else {
					$fields->push($hasOneField);
				}
			}
		}
		
		// only add relational fields if an ID is present
		if($this->obj->ID) {
			// add has_many relation fields
			if($this->obj->has_many() && ($this->includeRelations === true || isset($this->includeRelations['has_many']))) {
				foreach($this->obj->has_many() as $relationship => $component) {
					if($this->tabbed) {
						$relationTab = $fields->findOrMakeTab(
							"Root.$relationship", 
							$this->obj->fieldLabel($relationship)
						);
					}
					$relationshipFields = singleton($component)->summaryFields();
					$foreignKey = $this->obj->getComponentJoinField($relationship);
					$ctf = new ComplexTableField(
						$this,
						$relationship,
						$component,
						$relationshipFields,
						"getCMSFields", 
						"$foreignKey = " . $this->obj->ID
					);
					$ctf->setPermissions(TableListField::permissions_for_object($component));
					if($this->tabbed) {
						$fields->addFieldToTab("Root.$relationship", $ctf);
					} else {
						$fields->push($ctf);
					}
				}
			}

			if($this->obj->many_many() && ($this->includeRelations === true || isset($this->includeRelations['many_many']))) {
				foreach($this->obj->many_many() as $relationship => $component) {
					if($this->tabbed) {
						$relationTab = $fields->findOrMakeTab(
							"Root.$relationship", 
							$this->obj->fieldLabel($relationship)
						);
					}

					$relationshipFields = singleton($component)->summaryFields();
					$filterWhere = $this->obj->getManyManyFilter($relationship, $component);
					$filterJoin = $this->obj->getManyManyJoin($relationship, $component);
					$ctf =  new ComplexTableField(
						$this,
						$relationship,
						$component,
						$relationshipFields,
						"getCMSFields", 
						$filterWhere,
						'', 
						$filterJoin
					);
					$ctf->setPermissions(TableListField::permissions_for_object($component));
					$ctf->popupClass = "ScaffoldingComplexTableField_Popup";
					if($this->tabbed) {
						$fields->addFieldToTab("Root.$relationship", $ctf);
					} else {
						$fields->push($ctf);
					}
				}
			}
		}
		
		return $fields;
	}
 function Title()
 {
     return $this->addTitle ? $this->addTitle : parent::Title();
 }
Exemple #18
0
	/**
	 * @param $name string The fieldname
	 * @param $sourceClass string The source class of this field
	 * @param $fieldList array An array of field headings of Fieldname => Heading Text (eg. heading1)
	 * @param $fieldTypes array An array of field types of fieldname => fieldType (eg. formfield). Do not use for extra data/hiddenfields.
	 * @param $filterField string The field to filter by.  Give the filter value in $sourceFilter.  The value will automatically be set on new records.
	 * @param $sourceFilter string If $filterField has a value, then this is the value to filter by.  Otherwise, it is a SQL filter expression.
	 * @param $editExisting boolean (Note: Has to stay on this position for legacy reasons)
	 * @param $sourceSort string
	 * @param $sourceJoin string
	 */
	function __construct($name, $sourceClass, $fieldList = null, $fieldTypes, $filterField = null, 
						$sourceFilter = null, $editExisting = true, $sourceSort = null, $sourceJoin = null) {
		
		$this->fieldTypes = $fieldTypes;
		$this->filterField = $filterField;
		
		$this->editExisting = $editExisting;

		// If we specify filterField, then an implicit source filter of "filterField = sourceFilter" is used.
		if($filterField) {
			$this->filterValue = $sourceFilter;
			$sourceFilter = "\"$filterField\" = '" . Convert::raw2sql($sourceFilter) . "'";
		}
		parent::__construct($name, $sourceClass, $fieldList, $sourceFilter, $sourceSort, $sourceJoin);
	}
Exemple #19
0
	/**
	 * Return a field, such as a {@link ComplexTableField} that is
	 * used to show and manipulate data relating to this report.
	 * 
	 * Generally, you should override {@link columns()} and {@link records()} to make your report,
	 * but if they aren't sufficiently flexible, then you can override this method.
	 *
	 * @return FormField subclass
	 */
	function getReportField() {
		$columnTitles = array();
		$fieldFormatting = array();
		$csvFieldFormatting = array();
		$fieldCasting = array();
		
		// Parse the column information
		foreach($this->columns() as $source => $info) {
			if(is_string($info)) $info = array('title' => $info);
			
			if(isset($info['formatting'])) $fieldFormatting[$source] = $info['formatting'];
			if(isset($info['csvFormatting'])) $csvFieldFormatting[$source] = $info['csvFormatting'];
			if(isset($info['casting'])) $fieldCasting[$source] = $info['casting'];
			$columnTitles[$source] = isset($info['title']) ? $info['title'] : $source;
		}
		
		// To do: implement pagination
		$query = $this->sourceQuery($_REQUEST);
			
		$tlf = new TableListField('ReportContent', $this->dataClass(), $columnTitles);
		$tlf->setCustomQuery($query);
		$tlf->setShowPagination(true);
		$tlf->setPageSize(50);
		$tlf->setPermissions(array('export', 'print'));
		
		// Hack to figure out if we are printing
		if (isset($_REQUEST['url']) && array_pop(explode('/', $_REQUEST['url'])) == 'printall') {
			$tlf->setTemplate('SSReportTableField');
		}
		
		if($fieldFormatting) $tlf->setFieldFormatting($fieldFormatting);
		if($csvFieldFormatting) $tlf->setCSVFieldFormatting($csvFieldFormatting);
		if($fieldCasting) $tlf->setFieldCasting($fieldCasting);

		return $tlf;
	}
 /**
  * Creates and returns the result table field for resultsForm.
  * Uses {@link resultsTableClassName()} to initialise the formfield. 
  * Method is called from {@link ResultsForm}.
  *
  * @param array $searchCriteria passed through from ResultsForm 
  *
  * @return TableListField 
  */
 function getResultsTable($searchCriteria)
 {
     $summaryFields = $this->getResultColumns($searchCriteria);
     $className = $this->parentController->resultsTableClassName();
     $tf = new $className($this->modelClass, $this->modelClass, $summaryFields);
     $tf->setCustomQuery($this->getSearchQuery($searchCriteria));
     $tf->setPageSize($this->parentController->stat('page_length'));
     $tf->setShowPagination(true);
     // @todo Remove records that can't be viewed by the current user
     $tf->setPermissions(array_merge(array('view', 'export'), TableListField::permissions_for_object($this->modelClass)));
     // csv export settings (select all columns regardless of user checkbox settings in 'ResultsAssembly')
     $exportFields = $this->getResultColumns($searchCriteria, false);
     $tf->setFieldListCsv($exportFields);
     $url = '<a href=\\"' . $this->Link() . '/$ID/edit\\">$value</a>';
     $tf->setFieldFormatting(array_combine(array_keys($summaryFields), array_fill(0, count($summaryFields), $url)));
     return $tf;
 }
Exemple #21
0
 /**
  * Returns a FieldSet with which to create the main editing form.
  *
  * You can override this in your child classes to add extra fields - first
  * get the parent fields using parent::getCMSFields(), then use
  * addFieldToTab() on the FieldSet.
  * 
  * See {@link getSettingsFields()} for a different set of fields
  * concerned with configuration aspects on the record, e.g. access control
  *
  * @return FieldSet The fields to be displayed in the CMS.
  */
 function getCMSFields()
 {
     require_once "forms/Form.php";
     // Status / message
     // Create a status message for multiple parents
     if ($this->ID && is_numeric($this->ID)) {
         $linkedPages = $this->VirtualPages();
     }
     $parentPageLinks = array();
     if (isset($linkedPages)) {
         foreach ($linkedPages as $linkedPage) {
             $parentPage = $linkedPage->Parent;
             if ($parentPage) {
                 if ($parentPage->ID) {
                     $parentPageLinks[] = "<a class=\"cmsEditlink\" href=\"admin/show/{$linkedPage->ID}\">{$parentPage->Title}</a>";
                 } else {
                     $parentPageLinks[] = "<a class=\"cmsEditlink\" href=\"admin/show/{$linkedPage->ID}\">" . _t('SiteTree.TOPLEVEL', 'Site Content (Top Level)') . "</a>";
                 }
             }
         }
         $lastParent = array_pop($parentPageLinks);
         $parentList = "'{$lastParent}'";
         if (count($parentPageLinks) > 0) {
             $parentList = "'" . implode("', '", $parentPageLinks) . "' and " . $parentList;
         }
         $statusMessage[] = sprintf(_t('SiteTree.APPEARSVIRTUALPAGES', "This content also appears on the virtual pages in the %s sections."), $parentList);
     }
     if ($this->HasBrokenLink || $this->HasBrokenFile) {
         $statusMessage[] = _t('SiteTree.HASBROKENLINKS', "This page has broken links.");
     }
     $dependentNote = '';
     $dependentTable = new LiteralField('DependentNote', '<p></p>');
     // Create a table for showing pages linked to this one
     $dependentPagesCount = $this->DependentPagesCount();
     if ($dependentPagesCount) {
         $dependentColumns = array('Title' => $this->fieldLabel('Title'), 'AbsoluteLink' => _t('SiteTree.DependtPageColumnURL', 'URL'), 'DependentLinkType' => _t('SiteTree.DependtPageColumnLinkType', 'Link type'));
         if (class_exists('Subsite')) {
             $dependentColumns['Subsite.Title'] = singleton('Subsite')->i18n_singular_name();
         }
         $dependentNote = new LiteralField('DependentNote', '<p>' . _t('SiteTree.DEPENDENT_NOTE', 'The following pages depend on this page. This includes virtual pages, redirector pages, and pages with content links.') . '</p>');
         $dependentTable = new TableListField('DependentPages', 'SiteTree', $dependentColumns);
         $dependentTable->setCustomSourceItems($this->DependentPages());
         $dependentTable->setFieldFormatting(array('Title' => '<a href=\\"admin/show/$ID\\">$Title</a>', 'AbsoluteLink' => '<a href=\\"$value\\">$value</a>'));
         $dependentTable->setPermissions(array('show', 'export'));
     }
     $fields = new FieldSet($rootTab = new TabSet("Root", $tabMain = new Tab('Main', new TextField("Title", $this->fieldLabel('Title')), new TextField("MenuTitle", $this->fieldLabel('MenuTitle')), new HtmlEditorField("Content", _t('SiteTree.HTMLEDITORTITLE', "Content", PR_MEDIUM, 'HTML editor title'))), $tabMeta = new Tab('Metadata', new FieldGroup(_t('SiteTree.URL', "URL"), new LabelField('BaseUrlLabel', Controller::join_links(Director::absoluteBaseURL(), self::nested_urls() && $this->ParentID ? $this->Parent()->RelativeLink(true) : null)), new TextField("URLSegment", "URLSegment"), new LabelField('TrailingSlashLabel', "/")), new LiteralField('LinkChangeNote', self::nested_urls() && count($this->Children()) ? '<p>' . $this->fieldLabel('LinkChangeNote') . '</p>' : null), new HeaderField('MetaTagsHeader', $this->fieldLabel('MetaTagsHeader')), new TextField("MetaTitle", $this->fieldLabel('MetaTitle')), new TextareaField("MetaKeywords", $this->fieldLabel('MetaKeywords'), 1), new TextareaField("MetaDescription", $this->fieldLabel('MetaDescription')), new TextareaField("ExtraMeta", $this->fieldLabel('ExtraMeta'))), $tabDependent = new Tab('Dependent', $dependentNote, $dependentTable)));
     // Conditional dependent pages tab
     if ($dependentPagesCount) {
         $tabDependent->setTitle(_t('SiteTree.TABDEPENDENT', "Dependent pages") . " ({$dependentPagesCount})");
     } else {
         $fields->removeFieldFromTab('Root', 'Dependent');
     }
     $tabMain->setTitle(_t('SiteTree.TABCONTENT', "Content"));
     $tabMeta->setTitle(_t('SiteTree.TABMETA', "Metadata"));
     if (file_exists(BASE_PATH . '/install.php')) {
         $fields->addFieldToTab("Root.Main", new LiteralField("InstallWarningHeader", "<p class=\"message warning\">" . _t("SiteTree.REMOVE_INSTALL_WARNING", "Warning: You should remove install.php from this SilverStripe install for security reasons.") . "</p>"), "Title");
     }
     if (self::$runCMSFieldsExtensions) {
         $this->extend('updateCMSFields', $fields);
     }
     return $fields;
 }
 public function updateCMSFields(FieldSet $fields)
 {
     $fields->removeByName('Hash');
     $fields->replaceField('ViewedMembers', $members = new TableListField('ViewedMembers', 'Member', array('Name' => 'Name', 'Email' => 'Email'), '"Newsletter_TrackedLinkID" = ' . $this->owner->ID, null, 'LEFT JOIN "Newsletter_TrackedLink_ViewedMembers" ON "MemberID" = "Member"."ID"'));
     $members->setPermissions(array('show'));
 }
 /**
  * See class comments
  *
  * @param ContentController $controller
  * @param string $name
  * @param string $sourceClass
  * @param array $fieldList
  * @param FieldSet $detailFormFields
  * @param string $sourceFilter
  * @param string $sourceSort
  * @param string $sourceJoin
  */
 function __construct($controller, $name, $sourceClass, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "")
 {
     $this->detailFormFields = $detailFormFields;
     $this->controller = $controller;
     $this->pageSize = 10;
     Requirements::javascript("jsparty/greybox/AmiJS.js");
     Requirements::javascript("jsparty/greybox/greybox.js");
     Requirements::javascript('sapphire/javascript/TableListField.js');
     Requirements::javascript("sapphire/javascript/ComplexTableField.js");
     Requirements::css("jsparty/greybox/greybox.css");
     Requirements::css("sapphire/css/ComplexTableField.css");
     parent::__construct($name, $sourceClass, $fieldList, $sourceFilter, $sourceSort, $sourceJoin);
 }
 function BacklinkTable()
 {
     $dependentColumns = array('Title' => 'Title', 'Subsite.Title' => 'Subsite', 'AbsoluteLink' => 'URL', 'DependentLinkType' => 'Link type');
     if (!class_exists('Subsite')) {
         unset($dependentColumns['Subsite.Title']);
     }
     $dependentNote = new LiteralField('DependentNote', '<p>' . _t('SiteTree.DEPENDENT_NOTE', 'The following pages depend on this page. This includes virtual pages, redirector pages, and pages with content links.') . '</p>');
     $dependentTable = new TableListField('DependentPagesOnExpiry', 'SiteTree', $dependentColumns);
     $dependentTable->setCustomSourceItems($this->owner->DependentPages(false));
     $dependentTable->setFieldFormatting(array('Title' => '<a href=\\"admin/show/$ID\\">$Title</a>', 'AbsoluteLink' => '<a href=\\"$value\\">$value</a>'));
     $dependentTable->setPermissions(array('show', 'export'));
     return $dependentTable;
 }
 function FieldHolder()
 {
     Requirements::javascript('queuedjobs/javascript/QueuedJobListField.js');
     return parent::FieldHolder();
 }
 /**
  * Return a TableListField for viewing the related
  * BrokenLink records through the one-to-many relation.
  *
  * @return TableListField
  */
 public function brokenLinksTable()
 {
     // Get a singleton instance of BrokenLink
     $SNG_brokenLink = singleton('BrokenLink');
     // Set up the TableListField, for viewing BrokenLink
     // records that have the current LinkCheckRun ID
     $table = new TableListField('BrokenLinks', 'BrokenLink', $SNG_brokenLink->tableOverviewFields(), "\"LinkCheckRunID\" = {$this->ID}");
     $table->setFieldFormatting(array('PageTitle' => '<a href=\\"admin/show/$PageID\\">$PageTitle</a>', 'Link' => '<a href=\\"$Link\\">$Link</a>'));
     // Set permissions (we don't want to allow adding)
     $table->setPermissions(array('export'));
     $table->setPageSize(20);
     $table->setShowPagination(true);
     return $table;
 }
 function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->insertBefore(new LiteralField('Title', "<h2>Order #{$this->ID} - " . $this->dbObject('Created')->Nice() . " - " . $this->Member()->getName() . "</h2>"), 'Root');
     $fieldsAndTabsToBeRemoved = self::get_shipping_fields();
     $fieldsAndTabsToBeRemoved[] = 'Printed';
     $fieldsAndTabsToBeRemoved[] = 'MemberID';
     $fieldsAndTabsToBeRemoved[] = 'Attributes';
     $fieldsAndTabsToBeRemoved[] = 'SessionID';
     foreach ($fieldsAndTabsToBeRemoved as $field) {
         $fields->removeByName($field);
     }
     $htmlSummary = $this->renderWith("Order");
     $printlabel = !$this->Printed ? "Print Invoice" : "Print Invoice Again";
     //TODO: i18n
     $fields->addFieldsToTab('Root.Main', array(new LiteralField("PrintInvoice", '<p class="print"><a href="OrderReport_Popup/index/' . $this->ID . '?print=1" onclick="javascript: window.open(this.href, \'print_order\', \'toolbar=0,scrollbars=1,location=1,statusbar=0,menubar=0,resizable=1,width=800,height=600,left = 50,top = 50\'); return false;">' . $printlabel . '</a></p>')));
     $fields->addFieldToTab('Root.Main', new LiteralField('MainDetails', $htmlSummary));
     //TODO: re-introduce this when order status logs have some meaningful purpose
     $fields->removeByName('OrderStatusLogs');
     $orderItemsTable = new TableListField("OrderItems", "OrderItem", OrderItem::$summary_fields, "\"OrderID\" = " . $this->ID, "\"Created\" ASC", null);
     $orderItemsTable->setPermissions(array("view"));
     $orderItemsTable->setPageSize(10000);
     $orderItemsTable->addSummary("Total", array("Total" => array("sum", "Currency->Nice")));
     $fields->addFieldToTab('Root.Items', $orderItemsTable);
     $modifierTable = new TableListField("OrderModifiers", "OrderModifier", OrderModifier::$summary_fields, "\"OrderID\" = " . $this->ID . "", "\"Type\", \"Amount\" ASC, \"Created\" ASC", null);
     $modifierTable->setPermissions(array("view"));
     $modifierTable->setPageSize(10000);
     $fields->addFieldToTab('Root.Extras', $modifierTable);
     if ($m = $this->Member()) {
         $lastv = new TextField("MemberLastLogin", "Last login", $m->dbObject('LastVisited')->Nice());
         $fields->addFieldToTab('Root.Customer', $lastv->performReadonlyTransformation());
         //TODO: this should be scaffolded instead, or come from something like $member->getCMSFields();
         $fields->addFieldToTab('Root.Customer', new LiteralField("MemberSummary", $m->renderWith("Order_Member")));
     }
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }
 function __construct($name, $folder)
 {
     $this->folder = $folder;
     parent::__construct($name, "File", array("Title" => "Title", "LinkedURL" => "URL"), "", "Title");
     $this->Markable = true;
 }
Exemple #29
0
 /**
  * Returns a FieldSet with which to create the CMS editing form.
  *
  * You can override this in your child classes to add extra fields - first
  * get the parent fields using parent::getCMSFields(), then use
  * addFieldToTab() on the FieldSet.
  *
  * @return FieldSet The fields to be displayed in the CMS.
  */
 function getCMSFields()
 {
     require_once "forms/Form.php";
     Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/prototype/prototype.js");
     Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/behaviour/behaviour.js");
     Requirements::javascript(CMS_DIR . "/javascript/SitetreeAccess.js");
     Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
     Requirements::javascript(SAPPHIRE_DIR . '/javascript/UpdateURL.js');
     // Status / message
     // Create a status message for multiple parents
     if ($this->ID && is_numeric($this->ID)) {
         $linkedPages = $this->VirtualPages();
     }
     $parentPageLinks = array();
     if (isset($linkedPages)) {
         foreach ($linkedPages as $linkedPage) {
             $parentPage = $linkedPage->Parent;
             if ($parentPage) {
                 if ($parentPage->ID) {
                     $parentPageLinks[] = "<a class=\"cmsEditlink\" href=\"admin/show/{$linkedPage->ID}\">{$parentPage->Title}</a>";
                 } else {
                     $parentPageLinks[] = "<a class=\"cmsEditlink\" href=\"admin/show/{$linkedPage->ID}\">" . _t('SiteTree.TOPLEVEL', 'Site Content (Top Level)') . "</a>";
                 }
             }
         }
         $lastParent = array_pop($parentPageLinks);
         $parentList = "'{$lastParent}'";
         if (count($parentPageLinks) > 0) {
             $parentList = "'" . implode("', '", $parentPageLinks) . "' and " . $parentList;
         }
         $statusMessage[] = sprintf(_t('SiteTree.APPEARSVIRTUALPAGES', "This content also appears on the virtual pages in the %s sections."), $parentList);
     }
     if ($this->HasBrokenLink || $this->HasBrokenFile) {
         $statusMessage[] = _t('SiteTree.HASBROKENLINKS', "This page has broken links.");
     }
     $message = "STATUS: {$this->Status}<br />";
     if (isset($statusMessage)) {
         $message .= "NOTE: " . implode("<br />", $statusMessage);
     }
     $dependentNote = '';
     $dependentTable = new LiteralField('DependentNote', '<p></p>');
     // Create a table for showing pages linked to this one
     $dependentPagesCount = $this->DependentPagesCount();
     if ($dependentPagesCount) {
         $dependentColumns = array('Title' => $this->fieldLabel('Title'), 'AbsoluteLink' => _t('SiteTree.DependtPageColumnURL', 'URL'), 'DependentLinkType' => _t('SiteTree.DependtPageColumnLinkType', 'Link type'));
         if (class_exists('Subsite')) {
             $dependentColumns['Subsite.Title'] = singleton('Subsite')->i18n_singular_name();
         }
         $dependentNote = new LiteralField('DependentNote', '<p>' . _t('SiteTree.DEPENDENT_NOTE', 'The following pages depend on this page. This includes virtual pages, redirector pages, and pages with content links.') . '</p>');
         $dependentTable = new TableListField('DependentPages', 'SiteTree', $dependentColumns);
         $dependentTable->setCustomSourceItems($this->DependentPages());
         $dependentTable->setFieldFormatting(array('Title' => '<a href=\\"admin/show/$ID\\">$Title</a>', 'AbsoluteLink' => '<a href=\\"$value\\">$value</a>'));
         $dependentTable->setPermissions(array('show', 'export'));
     }
     // Lay out the fields
     $fields = new FieldSet($rootTab = new TabSet("Root", $tabContent = new TabSet('Content', $tabMain = new Tab('Main', new TextField("Title", $this->fieldLabel('Title')), new TextField("MenuTitle", $this->fieldLabel('MenuTitle')), new HtmlEditorField("Content", _t('SiteTree.HTMLEDITORTITLE', "Content", PR_MEDIUM, 'HTML editor title'))), $tabMeta = new Tab('Metadata', new FieldGroup(_t('SiteTree.URL', "URL"), new LabelField('BaseUrlLabel', Controller::join_links(Director::absoluteBaseURL(), self::nested_urls() && $this->ParentID ? $this->Parent()->RelativeLink(true) : null)), new UniqueRestrictedTextField("URLSegment", "URLSegment", "SiteTree", _t('SiteTree.VALIDATIONURLSEGMENT1', "Another page is using that URL. URL must be unique for each page"), "[^A-Za-z0-9-]+", "-", _t('SiteTree.VALIDATIONURLSEGMENT2', "URLs can only be made up of letters, digits and hyphens."), "", "", "", 50), new LabelField('TrailingSlashLabel', "/")), new LiteralField('LinkChangeNote', self::nested_urls() && count($this->Children()) ? '<p>' . $this->fieldLabel('LinkChangeNote') . '</p>' : null), new HeaderField('MetaTagsHeader', $this->fieldLabel('MetaTagsHeader')), new TextField("MetaTitle", $this->fieldLabel('MetaTitle')), new TextareaField("MetaKeywords", $this->fieldLabel('MetaKeywords'), 1), new TextareaField("MetaDescription", $this->fieldLabel('MetaDescription')), new TextareaField("ExtraMeta", $this->fieldLabel('ExtraMeta')))), $tabBehaviour = new Tab('Behaviour', new DropdownField("ClassName", $this->fieldLabel('ClassName'), $this->getClassDropdown()), new OptionsetField("ParentType", _t("SiteTree.PAGELOCATION", "Page location"), array("root" => _t("SiteTree.PARENTTYPE_ROOT", "Top-level page"), "subpage" => _t("SiteTree.PARENTTYPE_SUBPAGE", "Sub-page underneath a parent page (choose below)"))), $parentIDField = new TreeDropdownField("ParentID", $this->fieldLabel('ParentID'), 'SiteTree'), new CheckboxField("ShowInMenus", $this->fieldLabel('ShowInMenus')), new CheckboxField("ShowInSearch", $this->fieldLabel('ShowInSearch')), new CheckboxField("ProvideComments", $this->fieldLabel('ProvideComments')), new LiteralField("HomepageForDomainInfo", "<p>" . _t('SiteTree.NOTEUSEASHOMEPAGE', "Use this page as the 'home page' for the following domains: \n\t\t\t\t\t\t\t(separate multiple domains with commas)") . "</p>"), new TextField("HomepageForDomain", _t('SiteTree.HOMEPAGEFORDOMAIN', "Domain(s)", PR_MEDIUM, 'Listing domains that should be used as homepage'))), $tabToDo = new Tab(_t('SiteTree.TABTODO', 'To-do') . ($this->ToDo ? '**' : ''), new LiteralField("ToDoHelp", _t('SiteTree.TODOHELP', "<p>You can use this to keep track of work that needs to be done to the content of your site.  To see all your pages with to do information, open the 'Site Reports' window on the left and select 'To Do'</p>")), new TextareaField("ToDo", "", 10)), $tabDependent = new Tab('Dependent', $dependentNote, $dependentTable), $tabAccess = new Tab('Access', new HeaderField('WhoCanViewHeader', _t('SiteTree.ACCESSHEADER', "Who can view this page?"), 2), $viewersOptionsField = new OptionsetField("CanViewType", ""), $viewerGroupsField = new TreeMultiselectField("ViewerGroups", $this->fieldLabel('ViewerGroups')), new HeaderField('WhoCanEditHeader', _t('SiteTree.EDITHEADER', "Who can edit this page?"), 2), $editorsOptionsField = new OptionsetField("CanEditType", ""), $editorGroupsField = new TreeMultiselectField("EditorGroups", $this->fieldLabel('EditorGroups')))));
     /*
      * This filter ensures that the ParentID dropdown selection does not show this node,
      * or its descendents, as this causes vanishing bugs.
      */
     $parentIDField->setFilterFunction(create_function('$node', "return \$node->ID != {$this->ID};"));
     // Conditional dependent pages tab
     if ($dependentPagesCount) {
         $tabDependent->setTitle(_t('SiteTree.TABDEPENDENT', "Dependent pages") . " ({$dependentPagesCount})");
     } else {
         $fields->removeFieldFromTab('Root', 'Dependent');
     }
     // Make page location fields read-only if the user doesn't have the appropriate permission
     if (!Permission::check("SITETREE_REORGANISE")) {
         $fields->makeFieldReadonly('ParentType');
         if ($this->ParentType == 'root') {
             $fields->removeByName('ParentID');
         } else {
             $fields->makeFieldReadonly('ParentID');
         }
     }
     $viewersOptionsSource = array();
     $viewersOptionsSource["Inherit"] = _t('SiteTree.INHERIT', "Inherit from parent page");
     $viewersOptionsSource["Anyone"] = _t('SiteTree.ACCESSANYONE', "Anyone");
     $viewersOptionsSource["LoggedInUsers"] = _t('SiteTree.ACCESSLOGGEDIN', "Logged-in users");
     $viewersOptionsSource["OnlyTheseUsers"] = _t('SiteTree.ACCESSONLYTHESE', "Only these people (choose from list)");
     $viewersOptionsField->setSource($viewersOptionsSource);
     $editorsOptionsSource = array();
     $editorsOptionsSource["Inherit"] = _t('SiteTree.INHERIT', "Inherit from parent page");
     $editorsOptionsSource["LoggedInUsers"] = _t('SiteTree.EDITANYONE', "Anyone who can log-in to the CMS");
     $editorsOptionsSource["OnlyTheseUsers"] = _t('SiteTree.EDITONLYTHESE', "Only these people (choose from list)");
     $editorsOptionsField->setSource($editorsOptionsSource);
     if (!Permission::check('SITETREE_GRANT_ACCESS')) {
         $fields->makeFieldReadonly($viewersOptionsField);
         if ($this->CanViewType == 'OnlyTheseUsers') {
             $fields->makeFieldReadonly($viewerGroupsField);
         } else {
             $fields->removeByName('ViewerGroups');
         }
         $fields->makeFieldReadonly($editorsOptionsField);
         if ($this->CanEditType == 'OnlyTheseUsers') {
             $fields->makeFieldReadonly($editorGroupsField);
         } else {
             $fields->removeByName('EditorGroups');
         }
     }
     $tabContent->setTitle(_t('SiteTree.TABCONTENT', "Content"));
     $tabMain->setTitle(_t('SiteTree.TABMAIN', "Main"));
     $tabMeta->setTitle(_t('SiteTree.TABMETA', "Metadata"));
     $tabBehaviour->setTitle(_t('SiteTree.TABBEHAVIOUR', "Behavior"));
     $tabAccess->setTitle(_t('SiteTree.TABACCESS', "Access"));
     if (file_exists(BASE_PATH . '/install.php')) {
         $fields->addFieldToTab("Root.Content.Main", new LiteralField("InstallWarningHeader", "<p class=\"message warning\">" . _t("SiteTree.REMOVE_INSTALL_WARNING", "Warning: You should remove install.php from this SilverStripe install for security reasons.") . "</p>"), "Title");
     }
     if (self::$runCMSFieldsExtensions) {
         $this->extend('updateCMSFields', $fields);
     }
     return $fields;
 }
	function __construct($name, $sourceClass, $fieldList = null, $fieldTypes, $filterField = null, 
						$sourceFilter = null, $editExisting = true, $sourceSort = null, $sourceJoin = null) {
		
		$this->fieldTypes = $fieldTypes;
		$this->filterField = $filterField;
		
		$this->editExisting = $editExisting;

		// If we specify filterField, then an implicit source filter of "filterField = sourceFilter" is used.
		if($filterField) {
			$this->filterValue = $sourceFilter;
			$sourceFilter = "`$filterField` = '" . Convert::raw2sql($sourceFilter) . "'";
		}
		parent::__construct($name, $sourceClass, $fieldList, $sourceFilter, $sourceSort, $sourceJoin);

		Requirements::javascript(SAPPHIRE_DIR . "/javascript/i18n.js");
		Requirements::javascript(SAPPHIRE_DIR . '/javascript/TableField.js');
	}