function createImportForm(&$defaults)
 {
     $form = new Am_Form_Admin();
     /** count imported */
     $imported_products = $this->getDi()->db->selectCell("SELECT COUNT(id) FROM ?_data WHERE `table`='product' AND `key`='ym:id'");
     $memberTypes = unserialize($this->db_yourmembers->selectCell("SELECT option_value  FROM ?_options where option_name='ym_packs'"));
     $total = $memberTypes->getCount();
     if ($imported_products >= $total) {
         $cb = $form->addStatic()->setContent("Imported ({$imported_products} of {$total})");
     } else {
         $cb = $form->addRadio('import', array('value' => 'product'));
     }
     $cb->setLabel('Import Products');
     // Import coupons
     $imported_coupons = $this->getDi()->db->selectCell("SELECT COUNT(id) FROM ?_data WHERE `table`='coupon' AND `key`='ym:id'");
     $totalc = $this->db_yourmembers->selectCell("SELECT COUNT(*) FROM ?_ym_coupon");
     if ($imported_products) {
         if ($imported_coupons >= $totalc) {
             $cb = $form->addStatic()->setContent("Imported ({$imported_coupons} of {$totalc})");
         } else {
             $cb = $form->addRadio('import', array('value' => 'coupon'));
         }
         $cb->setLabel('Import Coupons');
     }
     if ($imported_products && ($imported_coupons || !$totalc)) {
         $imported_users = $this->getDi()->db->selectCell("SELECT COUNT(id) FROM ?_data WHERE `table`='user' AND `key`='ym:id'");
         $total = $this->db_yourmembers->selectCell("SELECT COUNT(*) FROM ?_users");
         if ($imported_users >= $total) {
             $cb = $form->addStatic()->setContent("Imported ({$imported_users})");
         } else {
             $cb = $form->addGroup();
             if ($imported_users) {
                 $cb->addStatic()->setContent("partially imported ({$imported_users} of {$total} total)<br /><br />");
             }
             $cb->addRadio('import', array('value' => 'user'));
             $cb->addStatic()->setContent('<br /><br /># of users (keep empty to import all) ');
             $cb->addInteger('user[count]');
         }
         $cb->setLabel('Import User and Payment Records');
     }
     $form->addSaveButton('Run');
     $defaults = array();
     return $form;
 }
 function createImportForm(&$defaults)
 {
     $form = new Am_Form_Admin();
     /** count imported */
     $imported_products = $this->getDi()->db->selectCell("SELECT COUNT(id) FROM ?_data WHERE `table`='product' AND `key`='am3:id'");
     $total = $this->db3->selectCell("SELECT COUNT(*) FROM ?_products");
     if ($imported_products >= $total) {
         $cb = $form->addStatic()->setContent("Imported ({$imported_products} of {$total})");
     } else {
         $cb = $form->addRadio('import', array('value' => 'product'));
     }
     $cb->setLabel('Import Products');
     if ($imported_products) {
         $imported_users = $this->getDi()->db->selectCell("SELECT COUNT(id) FROM ?_data WHERE `table`='user' AND `key`='am3:id'");
         $total = $this->db3->selectCell("SELECT COUNT(*) FROM ?_members");
         if ($imported_users >= $total) {
             $cb = $form->addStatic()->setContent("Imported ({$imported_users})");
         } else {
             $cb = $form->addGroup();
             if ($imported_users) {
                 $cb->addStatic()->setContent("partially imported ({$imported_users} of {$total} total)<br /><br />");
             }
             $cb->addRadio('import', array('value' => 'user'));
             $cb->addStatic()->setContent('<br /><br /># of users (keep empty to import all) ');
             $cb->addInteger('user[count]');
             $cb->addStatic()->setContent('<br />Do not import pending users');
             $cb->addCheckbox('user[exclude_pending]');
         }
         $cb->setLabel('Import User and Payment Records');
         if ($imported_users) {
             if ($this->getDi()->modules->isEnabled('aff')) {
                 $imported_comm = $this->getDi()->db->selectCell("SELECT COUNT(id) FROM ?_data WHERE `table`='aff_commission' AND `key`='am3:id'");
                 $total = $this->db3->selectCell("SELECT COUNT(*) FROM ?_aff_commission");
                 $gr = $form->addGroup()->setLabel('Import Affiliate Commissions and Refs');
                 if ($imported_comm) {
                     $gr->addStatic()->setContent("Imported ({$imported_comm} of {$total})");
                 } else {
                     $gr->addRadio('import', array('value' => 'aff'));
                 }
             } else {
                 $form->addStatic()->setContent('Enable [aff] module in Setup/Configuration to import information');
             }
             if ($this->getDi()->modules->isEnabled('newsletter')) {
                 $form->addRadio('import', array('value' => 'newsletter'))->setLabel('Import Newsletter Threads and Subscriptions');
             } else {
                 $form->addStatic()->setContent('Enable [newsletter] module in Setup/Configuration to import information');
             }
         }
     }
     $form->addSaveButton('Run');
     $defaults = array();
     return $form;
 }
 function createImportForm(&$defaults)
 {
     $form = new Am_Form_Admin();
     /** count imported */
     $imported_products = $this->getDi()->db->selectCell("SELECT COUNT(id) FROM ?_data WHERE `table`='product' AND `key`='am3:id'");
     $total = $this->db3->selectCell("SELECT COUNT(*) FROM ?_products");
     if ($total_products = $this->getDi()->db->selectCell("SELECT COUNT(*) FROM ?_product")) {
         $form->addStatic()->setLabel(___('Clean up v4 Database'))->setContent(sprintf(___('Use this %slink%s to delete data from aMember v4 database and use clean database for import'), '<a href="' . REL_ROOT_URL . '/admin-import3/clean">', '</a>'));
     }
     $cb = $form->addGroup();
     if ($imported_products >= $total) {
         $cb->addStatic()->setContent("Imported ({$imported_products} of {$total})");
     } else {
         $cb->addRadio('import', array('value' => 'product'));
     }
     $cb->setLabel('Import Products');
     $cb->addStatic()->setContent('<br />Keep the same Product  IDs');
     $keep_id_chkbox = $cb->addCheckbox('product[keep_product_id]');
     if ($imported_products < $total && $this->db3->selectCell("SELECT COUNT(*) FROM ?_products WHERE data like '%subusers_count%'") && !in_array('subusers', $this->getDi()->modules->getEnabled())) {
         $cb->addStatic()->setContent('<br />Enable [subusers] module in Setup/Configuration to import subusers information');
     }
     if ($total_products) {
         $keep_id_chkbox->setAttribute('disabled');
         $cb->addStatic()->setContent('Product table have records already. Please use Clean Up if you want to keep the same product IDs');
     }
     // Import coupons
     $imported_coupons = $this->getDi()->db->selectCell("SELECT COUNT(id) FROM ?_data WHERE `table`='coupon' AND `key`='am3:id'");
     $totalc = $this->db3->selectCell("SELECT COUNT(*) FROM ?_coupon");
     if ($imported_products) {
         if ($imported_coupons >= $totalc) {
             $cb = $form->addStatic()->setContent("Imported ({$imported_coupons} of {$totalc})");
         } else {
             $cb = $form->addRadio('import', array('value' => 'coupon'));
         }
         $cb->setLabel('Import Coupons');
     }
     //import folders without actual protection
     /*if ($imported_products)
       {
           $total = $this->db3->selectCell("SELECT COUNT(*) FROM ?_folders");
           if ($total){
               $cb = $form->addRadio('import', array('value' => 'folder'));
               $cb->setLabel('Import Folders');
           }
       }
       //import integrations
       if ($imported_products)
       {
           $cb = $form->addRadio('import', array('value' => 'integration'));
           $cb->setLabel('Import Integrations');
       }
       //import product links
       if ($imported_products)
       {
           $cb = $form->addRadio('import', array('value' => 'productlinks'));
           $cb->setLabel('Import Product Links');
       }*/
     if ($imported_products && ($imported_coupons || !$totalc)) {
         $imported_users = $this->getDi()->db->selectCell("SELECT COUNT(id) FROM ?_data WHERE `table`='user' AND `key`='am3:id'");
         $total = $this->db3->selectCell("SELECT COUNT(*) FROM ?_members");
         if ($imported_users >= $total) {
             $cb = $form->addStatic()->setContent("Imported ({$imported_users})");
         } else {
             $cb = $form->addGroup();
             if ($imported_users) {
                 $cb->addStatic()->setContent("partially imported ({$imported_users} of {$total} total)<br /><br />");
             }
             $cb->addRadio('import', array('value' => 'user'));
             $cb->addStatic()->setContent('<br /><br /># of users (keep empty to import all) ');
             $cb->addInteger('user[count]');
             $cb->addStatic()->setContent('<br />Do not import pending users');
             $cb->addCheckbox('user[exclude_pending]');
             $cb->addStatic()->setContent('<br />Keep the same user IDs');
             $keep_id_chkbox = $cb->addCheckbox('user[keep_user_id]');
             if ($this->getDi()->db->selectCell("SELECT COUNT(*) FROM ?_user")) {
                 $keep_id_chkbox->setAttribute('disabled');
                 $cb->addStatic()->setContent('User database have records already. Please use Clean Up if you want to keep the same user IDs');
             }
         }
         $cb->setLabel('Import User and Payment Records');
         if ($imported_users) {
             if ($this->getDi()->modules->isEnabled('aff')) {
                 $imported_comm = $this->getDi()->db->selectCell("SELECT COUNT(id) FROM ?_data WHERE `table`='aff_commission' AND `key`='am3:id'");
                 $total = $this->db3->selectCell("SELECT COUNT(*) FROM ?_aff_commission");
                 $imported_clicks = $this->getDi()->db->selectCell("SELECT COUNT(id) FROM ?_data WHERE `table`='aff_click' AND `key`='am3:id'");
                 $total_clicks = $this->db3->selectCell("SELECT COUNT(*) FROM ?_aff_clicks");
                 $gr = $form->addGroup()->setLabel('Import Affiliate Commissions and Refs');
                 if ($imported_comm >= $total) {
                     $gr->addStatic()->setContent("Imported ({$imported_comm} of {$total})");
                 } else {
                     if ($imported_comm) {
                         $gr->addStatic()->setContent("partially imported ({$imported_comm} of {$total} total)<br /><br />");
                     }
                     $gr->addRadio('import', array('value' => 'aff'));
                 }
                 $gr = $form->addGroup()->setLabel('Import Affiliate Clicks');
                 if ($imported_clicks >= $total_clicks) {
                     $gr->addStatic()->setContent("Imported ({$imported_clicks} of {$total_clicks})");
                 } else {
                     if ($imported_clicks) {
                         $gr->addStatic()->setContent("partially imported ({$imported_clicks} of {$total_clicks} total)<br /><br />");
                     }
                     $gr->addRadio('import', array('value' => 'affclicks'));
                 }
                 $gr = $form->addGroup()->setLabel('Import Affiliate Banners and Links');
                 $gr->addRadio('import', array('value' => 'affbanners'));
                 $gr->addStatic()->setContent("Workaround to have old links working");
             } else {
                 $form->addStatic()->setContent('Enable [aff] module in Setup/Configuration to import information');
             }
             if ($this->getDi()->modules->isEnabled('newsletter')) {
                 $form->addRadio('import', array('value' => 'newsletter'))->setLabel('Import Newsletter Threads and Subscriptions');
             } else {
                 $form->addStatic()->setContent('Enable [newsletter] module in Setup/Configuration to import information');
             }
         }
     }
     //import PAYPAL_PROFILE_ID for previously wrongly imported invoices
     /*if ($imported_users)
       {
           $total = $this->db3->selectCell("SELECT COUNT(*) FROM ?_folders");
           if ($total){
               $cb = $form->addRadio('import', array('value' => 'paypalprofileid'));
               $cb->setLabel("Import Paypal Profile ID's");
           }
       }*/
     $form->addSaveButton('Run');
     $defaults = array();
     return $form;
 }
 function createImportForm(&$defaults)
 {
     $form = new Am_Form_Admin();
     /** count imported */
     $imported_products = $this->getDi()->db->selectCell("SELECT COUNT(id) FROM ?_data WHERE `table`='product' AND `key`='oss6:id'");
     $total = $this->db_oss->selectCell("SELECT COUNT(*) FROM ?_groups");
     if ($imported_products >= $total) {
         $cb = $form->addStatic()->setContent("Imported ({$imported_products} of {$total})");
     } else {
         $cb = $form->addRadio('import', array('value' => 'product'));
     }
     $cb->setLabel('Import Products');
     if ($imported_products) {
         $imported_users = $this->getDi()->db->selectCell("SELECT COUNT(id) FROM ?_data WHERE `table`='user' AND `key`='oss6:id'");
         $total = $this->db_oss->selectCell("SELECT COUNT(*) FROM ?_users");
         if ($imported_users >= $total) {
             $cb = $form->addStatic()->setContent("Imported ({$imported_users})");
         } else {
             $cb = $form->addGroup();
             if ($imported_users) {
                 $cb->addStatic()->setContent("partially imported ({$imported_users} of {$total} total)<br /><br />");
             }
             $cb->addRadio('import', array('value' => 'user'));
             $cb->addStatic()->setContent('<br /><br /># of users (keep empty to import all) ');
             $cb->addInteger('user[count]');
         }
         $cb->setLabel('Import User and Payment Records');
     }
     $form->addSaveButton('Run');
     $defaults = array();
     return $form;
 }
 function createImportForm(&$defaults)
 {
     $form = new Am_Form_Admin();
     /** count imported */
     $imported_products = $this->getDi()->db->selectCell("SELECT COUNT(id) FROM ?_data WHERE `table`='product' AND `key`='wom:id'");
     $wopCfg = $this->db_wordpress->selectCell("SELECT option_value FROM ?_options WHERE option_name = ?", 'ws_plugin__optimizemember_options');
     $wopCfg = unserialize($wopCfg);
     if (is_array($wopCfg)) {
         $amProducts = array('' => '-- Please Select --') + $this->getDi()->productTable->getOptions();
         $womProducts = array();
         for ($i = 0; $i <= 10; $i++) {
             $womProducts['level' . ($i ? $i : '')] = $wopCfg['level' . $i . '_label'];
         }
         if ($imported_products) {
             $cb = $form->addStatic()->setContent("Linked");
         } else {
             $cb = $form->addRadio('import', array('value' => 'product'));
             foreach ($womProducts as $key => $value) {
                 $form->addSelect("pr_link[" . $key . "]")->setLabel($value)->loadOptions($amProducts);
             }
             $form->addRule('callback2', '-error-', array($this, 'validateForm'));
         }
         $cb->setLabel('Link Products');
     }
     if (!is_array($wopCfg) || $imported_products) {
         $imported_users = $this->getDi()->db->selectCell("SELECT COUNT(id) FROM ?_data WHERE `table`='user' AND `key`='wom:id'");
         $total = $this->db_wordpress->selectCell("SELECT COUNT(*) FROM ?_users");
         if ($imported_users >= $total) {
             $cb = $form->addStatic()->setContent("Imported ({$imported_users})");
         } else {
             $cb = $form->addGroup();
             if ($imported_users) {
                 $cb->addStatic()->setContent("partially imported ({$imported_users} of {$total} total)<br /><br />");
             }
             $cb->addRadio('import', array('value' => 'user'));
             $cb->addStatic()->setContent('<br /><br /># of users (keep empty to import all) ');
             $cb->addInteger('user[count]');
             $cb->addStatic()->setContent('<br />Keep the same user IDs');
             $keep_id_chkbox = $cb->addCheckbox('user[keep_user_id]');
             if ($this->getDi()->db->selectCell("SELECT COUNT(*) FROM ?_user")) {
                 $keep_id_chkbox->setAttribute('disabled');
                 $cb->addStatic()->setContent('User database have records already. Please use Clean Up if you want to keep the same user IDs');
             }
         }
         $cb->setLabel('Import User and Payment Records');
     }
     $form->addSaveButton('Run');
     $defaults = array();
     return $form;
 }
 function createImportForm(&$defaults)
 {
     $form = new Am_Form_Admin();
     /** count imported */
     $imported_products = $this->getDi()->db->selectCell("SELECT COUNT(id) FROM ?_data WHERE `table`='product' AND `key`='ipb_nexus:id'");
     $total = $this->db_ipb_nexus->selectCell("SELECT COUNT(*) FROM ?_nexus_packages");
     if ($this->getDi()->db->selectCell("SELECT COUNT(*) FROM ?_product")) {
         $form->addStatic()->setLabel(___('Clean up v4 Database'))->setContent(sprintf(___('Use this %slink%s to delete data from aMember v4 database and use clean database for import'), '<a href="' . REL_ROOT_URL . '/admin-import-ipb-nexus/clean">', '</a>'));
     }
     if ($imported_products >= $total) {
         $cb = $form->addStatic()->setContent("Imported ({$imported_products} of {$total})");
     } else {
         $cb = $form->addRadio('import', array('value' => 'product'));
     }
     $cb->setLabel('Import Products');
     if ($imported_products) {
         $imported_users = $this->getDi()->db->selectCell("SELECT COUNT(id) FROM ?_data WHERE `table`='user' AND `key`='ipb_nexus:id'");
         $total = $this->db_ipb_nexus->selectCell("SELECT COUNT(*) FROM ?_members");
         if ($imported_users >= $total) {
             $cb = $form->addStatic()->setContent("Imported ({$imported_users})");
         } else {
             $cb = $form->addGroup();
             if ($imported_users) {
                 $cb->addStatic()->setContent("partially imported ({$imported_users} of {$total} total)<br /><br />");
             }
             $cb->addRadio('import', array('value' => 'user'));
             $cb->addStatic()->setContent('<br /><br /># of users (keep empty to import all) ');
             $cb->addInteger('user[count]');
         }
         $cb->setLabel('Import User and Payment Records');
     }
     $form->addSaveButton('Run');
     $defaults = array();
     return $form;
 }