<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/
class Fields_Form_Admin_Type extends Engine_Form
{
  public function init()
  {

    $metaTable = Engine_Api::_()->fields()->getTable('user', 'meta');
    $select = $metaTable->select()->where('type = ?', 'profile_type');
    $profileType = $metaTable->fetchRow($select);

    // Get list of Member Types
    $db = Engine_Db_Table::getDefaultAdapter();
    $memberTypeResult = $db->select('option_id, label')
            ->from('engine4_user_fields_options')
            ->where('field_id = ?', $profileType->field_id)
            ->query()
            ->fetchAll();
    $memberTypeCount = engine_count($memberTypeResult);
    $memberTypeArray = array( 'null' => 'No, Create Blank Profile Type' );
    for( $i = 0; $i < $memberTypeCount; $i++ ) {
      $memberTypeArray[$memberTypeResult[$i]['option_id']] = $memberTypeResult[$i]['label'];
    }

    $this->setMethod('POST')
      ->setAttrib('class', 'global_form_popup');

    // Add label
    $this->addElement('Text', 'label', array(
      'label' => 'Profile Type Label',
      'required' => true,
      'allowEmpty' => false,
    ));

    // Duplicate Existing
    $this->addElement('Select', 'duplicate', array(
      'label' => 'Duplicate Existing Profile Type?',
      'required' => true,
      'allowEmpty' => false,
      'multiOptions' => $memberTypeArray,
    ));


    // Add submit
    $this->addElement('Button', 'save', array(
      'label' => 'Add Profile Type',
      'type' => 'submit',
      'onClick' => 'disableSubmit(this);',
      'decorators' => array(
        'ViewHelper',
      ),
    ));

    // Add cancel
    $this->addElement('Cancel', 'cancel', array(
      'label' => 'cancel',
      'link' => true,
      'onclick' => 'parent.Smoothbox.close();',
      'prependText' => ' or ',
      'decorators' => array(
        'ViewHelper',
      ),
    ));

    $this->addDisplayGroup(array('save', 'cancel'), 'buttons');
  }
}
