<?php
/*+*******************************************************************************
 * The content of this file is subject to the CRMTiger Pro license.
 * ("License"); You may not use this file except in compliance with the License
 * The Initial Developer of the Original Code is vTiger
 * The Modified Code of the Original Code owned by https://crmtiger.com/
 * Portions created by CRMTiger.com are Copyright(C) CRMTiger.com
 * All Rights Reserved.
  ***************************************************************************** */
class CTMobileSettings_SaveSearchAjax_Action extends Vtiger_Save_Action {
    public function process(Vtiger_Request $request) {
        global $adb;
        $search_module=$request->get("search_module");
        $active=$request->get("active");
        $field=$request->get("search_field");
        $search_users=$request->get("search_users");
       
        if(is_array($search_users)) {
            foreach($search_users as $userid) {
                // Clear data
                $adb->pquery("DELETE FROM `ctmobile_search_field` WHERE `module`=? AND userid = ?",array($search_module,$userid));

                // Save selected fields
                $adb->pquery("INSERT INTO `ctmobile_search_field` (`module`,`fieldname`,`userid`) VALUES (?,?,?)",array($search_module,$field,$userid));
            }
        }
           
        $response = new Vtiger_Response();
        $response->setEmitType(Vtiger_Response::$EMIT_JSON);
        $response->setResult(array('_module'=>$search_module));
        $response->emit();
    }
}
