<div class="row">
    <div class="container">

        <ol class="breadcrumb">
            <li><a href="#">خصائص عامة</a></li>
            <li><a href="userController.php?do=show">المستخدمين</a></li>
            <li class="active">تعديل مستخدم</li>
        </ol>


        <div class="panel panel-default panel-m">
            <div class="panel-heading">
                <h3 class="panel-title">تعديل مستخدم</h3>
            </div>
            <div class="panel-body">
                <form class="form-horizontal" role="form" action="userController.php?do=update" method="post"
                      id="spform">




                    <div class="form-group">
                        <label for="username" class="col-lg-2 control-label">اسم المستخدم</label>
                        <div class="col-lg-4">

                            <span id="name">
                                <input type="text" class="form-control" placeholder="اسم المستخدم" name="username"
                                       id="username" value="{$loadData->username}">
                                <span class="textfieldRequiredMsg">*</span></span>


                            <div id="nameError" class="alert alert-block alert-danger fade in" style="display:none">
                                <button type="button" class="close pull-left" data-dismiss="alert"
                                        aria-hidden="true">&times;</button>
                                <h4>رسالة خطا</h4>
                                <p>هذا الاسم مستخدم من قبل</p>

                                <div class="clearfix"></div>
                            </div>


                        </div>
                    </div>


                    <div class="form-group">
                        <label for="password" class="col-lg-2 control-label">كلمة المرور</label>
                        <div class="col-lg-4">

                            <span id="sprytextfield1">
                                <input type="password" name="password" class="form-control" placeholder="كلمة المرور"
                                       value="{$loadData->password}" />
                                <span class="textfieldRequiredMsg">*</span></span>

                        </div>
                    </div>



                    <div class="form-group">
                        <label for="employeename" class="col-lg-2 control-label">اسم الموظف</label>
                        <div class="col-lg-4">

                            <span id="sprytextfield2">
                                <input type="text" class="form-control" placeholder="اسم الموظف" name="employeename"
                                       value="{$loadData->employeename}">
                                <span class="textfieldRequiredMsg">*</span></span>

                        </div>
                    </div>

                    <div class="form-group">
                        <label for="userstoreid" class="col-lg-2 control-label">السؤال السرى<span
                                style="color: red;display: block">فى حالة نسيت كلمة المرور</span></label>
                        <div class="col-lg-4">
                            <textarea class="form-control" name="question" rows="3"
                                      required>{$loadData->question}</textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="userstoreid" class="col-lg-2 control-label">الاجابة السرية<span
                                style="color: red;display: block">فى حالة نسيت كلمة المرور</span></label>
                        <div class="col-lg-4">
                            <textarea class="form-control" name="answer" rows="3"
                                      required>{$loadData->answer}</textarea>
                        </div>
                    </div>


                    <div {if $loginUsergroupData->editUserPrivlage neq 1 && $loginUsergroupid>0}class="hidden"{/if}>
                        <div class="form-group">
                            <label for="usergroupid" class="col-lg-2 control-label">المجموعة</label>
                            <div class="col-lg-4">


                                <span id="spryselect2">
                                    <select class="select2 wdt100" name="usergroupid" id="usergroupid">

                                        {foreach $UserGroupData as $UserGroup}

                                        <option {if {$loadData->usergroupid} eq {$UserGroup->usergroupid}}
                                            selected="selected" {/if}
                                            value="{$UserGroup->usergroupid}">{$UserGroup->usergroupname}</option>

                                        {/foreach}

                                    </select>
                                    <span class="selectInvalidMsg"> *</span></span>
                            </div>
                        </div>


                        <!--------------------------------------------->

                        <!--------------------------------------------->

                        <div class="form-group">
                            <label for="usergroupid" class="col-lg-2 control-label"> الفرع</label>
                            <div class="col-lg-4">

                                <select required class="select2 wdt100" name="branchid" id="branchid">
                                    <option value="-1">اختر الفرع</option>
                                    <option value="0" {if {$loadData->branchId} eq 0} selected="selected" {/if}> كل
                                        الفروع</option>

                                    {foreach $allbranchdata as $myallbranchdata}

                                    <option {if {$loadData->branchId} eq {$myallbranchdata->branchId}}
                                        selected="selected" {/if}
                                        value="{$myallbranchdata->branchId}">{$myallbranchdata->branchName}</option>
                                    {/foreach}


                                </select>

                            </div>
                        </div>

                        <!-------------------------------------->


                        <div class="form-group">
                            <label for="employeename" class="col-lg-2 control-label">نسبه {if
                                $Programsettingdata->delegate_seller eq 0} بائع {elseif
                                $Programsettingdata->delegate_seller == 1}مندوب {elseif
                                $Programsettingdata->delegate_seller == 2}طبيب {/if}</label>
                            <div class="col-lg-4"><span id="sprytextfield3">
                                    <input type="text" class="form-control"
                                           placeholder="نسبه {if $Programsettingdata->delegate_seller eq 0} بائع {elseif $Programsettingdata->delegate_seller == 1}مندوب {elseif $Programsettingdata->delegate_seller == 2}طبيب {/if}"
                                           value="{$loadData->awardrate}" name="awardrate" />
                                    <span class="textfieldRequiredMsg">***.</span><span
                                        class="textfieldInvalidFormatMsg">ادخل رقم مناسب.</span><span
                                        class="textfieldMaxValueMsg"> ادخل رقم من 0 الى 100</span><span
                                        class="textfieldMinValueMsg"> ادخل رقم من 0 الى 100</span></span></div>
                        </div>

                           <div class="form-group">
                        <label for="employeename" class="col-lg-2 control-label">نسبه {if {$Programsettingdata->delegate_seller} eq 0} بائع {else}مندوب {/if} جملة</label>
                        <div class="col-lg-4"><span id="sprytextfield3">
                                <input type="text"  class="form-control" placeholder="نسبه {if {$Programsettingdata->delegate_seller} eq 0} بائع {else}مندوب {/if} جملة" value="{$loadData->awardrategomla}" name="awardrategomla" />
                                <span class="textfieldRequiredMsg">***.</span><span class="textfieldInvalidFormatMsg">ادخل رقم مناسب.</span><span class="textfieldMaxValueMsg"> ادخل رقم من 0 الى 100</span><span class="textfieldMinValueMsg"> ادخل رقم من 0 الى 100</span></span></div>
                    </div>

                    <div class="form-group">
                        <label for="employeename" class="col-lg-2 control-label">نسبه {if {$Programsettingdata->delegate_seller} eq 0} بائع {else}مندوب {/if} نصف جملة</label>
                        <div class="col-lg-4"><span id="sprytextfield3">
                                <input type="text"  class="form-control" placeholder="نسبه {if {$Programsettingdata->delegate_seller} eq 0} بائع {else}مندوب {/if} نصف جملة" value="{$loadData->awardratehalf}" name="awardratehalf" />
                                <span class="textfieldRequiredMsg">***.</span><span class="textfieldInvalidFormatMsg">ادخل رقم مناسب.</span><span class="textfieldMaxValueMsg"> ادخل رقم من 0 الى 100</span><span class="textfieldMinValueMsg"> ادخل رقم من 0 الى 100</span></span></div>
                    </div>

                        <!--------------------------------------------->



                        <div class="form-group">
                            <label for="saveid" class="col-lg-2 control-label">الخزنة الافتراضية</label>
                            <div class="col-lg-4">

                                <span id="spryselect3">
                                    <select class="select2 wdt100" name="saveid" id="saveid">


                                        {foreach $saveData as $save}

                                        <option {if {$loadData->saveid} eq {$save->saveid}} selected="selected" {/if}
                                            value="{$save->saveid}">{$save->savename}</option>

                                        {/foreach}


                                    </select>
                                    <span class="selectInvalidMsg"> *</span></span>
                            </div>
                        </div>




                        <!--

                        <div class="form-group">
                            <label for="saveid" class="col-lg-2 control-label">البحث فى يوميه الخزنه</label>
                            <div class="col-lg-4">


                                <select class="select2 wdt100" name="searchinonesave" id="searchinonesave">
                                    <option   {if {$loadData->searchinonesave} eq 0} selected="selected" {/if}  value="0">كل الخزن</option>
                                    <option {if {$loadData->searchinonesave} eq 1} selected="selected" {/if} value="1">خزنه المستخدم فقط</option>
                                </select>

                            </div>
                        </div> -->



                        <div class="form-group">
                            <label for="saveid" class="col-lg-2 control-label">خزن المستخدم </label>
                            <div class="col-lg-4">
                                <div class="radio-inline">
                                    <label>
                                        <input value="0" class="radioR searchinonesave" name="searchinonesave"
                                               type="radio" {if {$loadData->searchinonesave} eq 0} checked {/if} />

                                        خزن متعدده</label>
                                </div>
                                <div class="radio-inline">
                                    <label>
                                        <input value="1" class="radioR searchinonesave" name="searchinonesave"
                                               type="radio" {if {$loadData->searchinonesave} eq 1} checked {/if} />
                                        خزنه المستخدم فقط </label>
                                </div>

                            </div>
                        </div>



                        <div class="form-group" id="saveidshow" {if {$loadData->searchinonesave} eq 1} style="display:
                            none;" {/if}>
                            <label for="userstoreid" class="col-lg-2 control-label">الخزن</label>
                            <div class="col-lg-4">

                                <span id="spryselect4">
                                    <select class="select2 wdt100" name="saveids[]" id="saveids" multiple=""
                                            data-placeholder="اختر الخزن">
                                        <option value="0" {if 0|in_array:$loadData->saveids} selected="selected" {/if}
                                            >كل الخزن </option>
                                        {foreach $saveData as $save}
                                        <option value="{$save->saveid}" {if $save->saveid|in_array:$loadData->saveids}
                                            selected="selected" {/if}>{$save->savename}</option>
                                        {/foreach}

                                    </select>
                                    <span class="selectInvalidMsg"> *</span></span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="saveid" class="col-lg-2 control-label">خزنة التصفية</label>
                            <div class="col-lg-4">
                                <span id="spryselect6">
                                    <select class="select2 wdt100" name="closeSavid" id="closeSavid">
                                        <option value="-1">اختر خزنة</option>
                                        {foreach $saveData as $save}
                                        <option value="{$save->saveid}" {if $loadData->closeSavid eq
                                            $save->saveid}selected{/if}>{$save->savename}</option>
                                        {/foreach}
                                    </select>
                                    <span class="selectInvalidMsg"> *</span></span>
                            </div>
                        </div>


                        <div class="form-group">
                            <label class="col-lg-2 control-label">البحث في رصيد المخازن </label>
                            <div class="col-lg-4">
                                <div class="radio-inline">
                                    <label>
                                        <input value="0" class="radioR" name="searchinonestorebalance" type="radio" {if
                                               {$loadData->searchinonestorebalance} eq 0} checked {/if}/>

                                        نعم </label>
                                </div>
                                <div class="radio-inline">
                                    <label>
                                        <input value="1" class="noradioR" name="searchinonestorebalance" type="radio"
                                               {if {$loadData->searchinonestorebalance} eq 1} checked {/if}/>
                                        لا </label>
                                </div>

                            </div>
                        </div>


                        <div class="form-group">
                            <label for="userstoreidDef" class="col-lg-2 control-label">المخزن الافتراضى</label>
                            <div class="col-lg-4">

                                <span id="spryselect5">
                                    <select class="select2 wdt100" name="userstoreidDef" id="userstoreidDef"
                                            required="">
                                        <option value="-1">اختر المخزن</option>
                                        {foreach $storData as $mystorData}

                                        <option value="{$mystorData->storeId}" {if {$loadData->userstoreidDef} eq
                                            {$mystorData->storeId}} selected="selected" {/if}>{$mystorData->storeName}
                                        </option>

                                        {/foreach}


                                    </select>
                                    <span class="selectInvalidMsg"> *</span></span>
                            </div>
                        </div>







                        <div class="form-group">
                            <label for="userstoreid" class="col-lg-2 control-label">المخزن</label>
                            <div class="col-lg-4">

                                <span id="spryselect4">
                                    <select class="select2 wdt100" name="userstoreid" id="userstoreid" required="">
                                        <option value="-1">اختر المخزن</option>
                                        <option value="0" {if {$loadData->userstoreid} eq '0'} selected="selected"
                                            {/if}> مخازن متعدده</option>
                                        {foreach $storData as $mystorData}

                                        <option value="{$mystorData->storeId}" {if {$loadData->userstoreid} eq
                                            {$mystorData->storeId}} selected="selected" {/if}>{$mystorData->storeName}
                                        </option>

                                        {/foreach}


                                    </select>
                                    <span class="selectInvalidMsg"> *</span></span>
                            </div>
                        </div>


                        <div class="form-group" id="storeidshow" {if {$loadData->userstoreid} neq 0} style="display:
                            none;" {/if}>
                            <label for="storeids" class="col-lg-2 control-label">المخازن</label>
                            <div class="col-lg-4">

                                <span id="spryselect4">
                                    <select class="select2 wdt100" name="storeids[]" id="storeids" multiple=""
                                            data-placeholder="اختر ">
                                        <option value="0" {if 0|in_array:$loadData->storeids} selected="selected"
                                            {/if}>كل المخازن </option>
                                        {foreach $storData as $mystorData}
                                        <option value="{$mystorData->storeId}" {if $mystorData->
                                            storeId|in_array:$loadData->storeids} selected="selected"
                                            {/if}>{$mystorData->storeName}</option>
                                        {/foreach}
                                    </select>
                                    <span class="selectInvalidMsg"> *</span></span>
                            </div>
                        </div>
                        <!--==============================-->


                        <!--==============================-->
                        {if $loginUsergroupid == 1}
                        <div class="form-group">
                            <label class="col-lg-2 control-label">حفظ مباشر "بصريات"</label>
                            <div class="col-lg-4">
                                <div class="radio-inline">
                                    <label>
                                        <input value="1" class="radioR" name="directSaveBills" {if
                                               {$loadData->directSaveBills} eq 1} checked {/if} type="radio" />

                                        نعم </label>
                                </div>
                                <div class="radio-inline">
                                    <label>
                                        <input value="0" class="noradioR" name="directSaveBills" {if
                                               {$loadData->directSaveBills} eq 0} checked {/if} type="radio" />
                                        لا </label>
                                </div>

                            </div>
                        </div>
                        {/if}

                        <!--==============================-->
                        {if $programsetting->mandobCollectionRatio == 1}
                        <div class="form-group">
                            <label class="col-lg-2 control-label">الموظف</label>
                            <div class="col-lg-4">
                                <input type="text" class="form-control" readonly value="{$loadData->empName}">
                            </div>
                        </div>
                        {/if}
                        <div class="form-group">
                            <label class="col-lg-2 control-label">الاطلاع على العملاء</label>
                            <div class="col-lg-4">
                                <div class="radio-inline">
                                    <label>
                                        <input value="1" class="radioR" name="viewclients" type="radio" {if
                                               {$loadData->viewclients} eq 1} checked {/if} />

                                        جميع العملاء </label>
                                </div>
                                <div class="radio-inline">
                                    <label>
                                        <input value="0" class="noradioR" name="viewclients" type="radio" {if
                                               {$loadData->viewclients} eq 0} checked {/if}/>
                                        عملائى فقط </label>
                                </div>

                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-2 control-label">الاطلاع على الفواتير</label>
                            <div class="col-lg-6">
                                <div class="radio-inline">
                                    <label>
                                        <input value="1" class="radioR" name="viewbills" type="radio" {if
                                               {$loadData->viewbills} eq 1} checked {/if}/>

                                        جميع الفواتير</label>
                                </div>
                                <div class="radio-inline">
                                    <label>
                                        <input value="0" class="noradioR" name="viewbills" type="radio" {if
                                               {$loadData->viewbills} eq 0} checked {/if}/>
                                        فواتيري فقط </label>
                                </div>
                                <div class="radio-inline">
                                    <label>
                                        <input value="2" class="noradioR" name="viewbills" type="radio" {if
                                               {$loadData->viewbills} eq 2} checked {/if}/>
                                        فواتير مجموعة المستخدم </label>
                                </div>
                                <div class="radio-inline">
                                    <label>
                                        <input value="3" class="noradioR" name="viewbills" type="radio" {if
                                               {$loadData->viewbills} eq 3} checked {/if}/>
                                        مخازني فقط </label>
                                </div>

                            </div>
                        </div>
                        <!--==============================-->

                        <div class="form-group">
                            <label class="col-lg-2 control-label">مشرف مخزن</label>
                            <div class="col-lg-4">
                                <div class="radio-inline">
                                    <label>
                                        <input value="1" class="radioR" name="storeSupervisor" type="radio" {if
                                               {$loadData->storeSupervisor} eq 1} checked {/if} />

                                        نعم </label>
                                </div>
                                <div class="radio-inline">
                                    <label>
                                        <input value="0" class="noradioR" name="storeSupervisor" type="radio" {if
                                               {$loadData->storeSupervisor} eq 0} checked {/if}/>
                                        لا </label>
                                </div>

                            </div>
                        </div>
                        <!--==============================-->
                        <div class="form-group" style="display: none" id="storeSupervisorStoresDiv">
                            <label class="col-lg-2 control-label">مخازن المشرف</label>
                            <div class="col-lg-4">
                                <select class="select2" name="storeSupervisorStores[]" id="storeSupervisorStores"
                                        multiple="multiple" allowClear>
                                    <!--<option value="-1">كل المخازن</option>-->
                                    {foreach $storData as $mystorData}
                                    <option value="{$mystorData->storeId}" {if $mystorData->
                                        storeId|in_array:$loadData->storeSupervisorStores}selected{/if}>{$mystorData->storeName}
                                    </option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>


                        <div class="form-group">
                            <label for="userstoreid" class="col-lg-2 control-label">المشروعات</label>
                            <div class="col-lg-4">

                                <span id="spryselect4">
                                    <select class="select2 wdt100" name="projectids[]" id="projectids" multiple=""
                                            data-placeholder="اختر المشروعات">
                                        <option value="0" {if 0|in_array:$loadData->projectids} selected="selected"
                                            {/if}>كل المشروعات </option>
                                        {foreach $allprojectdata as $allproject}
                                        <option value="{$allproject->id}" {if $allproject->
                                            id|in_array:$loadData->projectids} selected="selected"
                                            {/if}>{$allproject->name}</option>
                                        {/foreach}

                                    </select>
                                    <span class="selectInvalidMsg"> *</span></span>
                            </div>
                        </div>







                        <div class="form-group">
                            <label for="userstoreid" class="col-lg-2 control-label">البنوك</label>
                            <div class="col-lg-4">

                                <span id="spryselect4">
                                    <select class="select2 wdt100" name="bankids[]" id="bankids" multiple=""
                                            data-placeholder="اختر البنوك">
                                        <option value="0" {if 0|in_array:$loadData->bankids} selected="selected" {/if}
                                            >كل البنوك </option>
                                        {foreach $allbankdata as $allbank}
                                        <option value="{$allbank->bankid}" {if $allbank->
                                            bankid|in_array:$loadData->bankids} selected="selected" {/if}
                                            >{$allbank->bankname}</option>
                                        {/foreach}

                                    </select>
                                    <span class="selectInvalidMsg"> *</span></span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="charityids" class="col-lg-2 control-label">الجمعيات</label>
                            <div class="col-lg-4">
                                <span id="spryselect4">
                                    <select class="select2 wdt100" name="charityids[]" id="charityids" multiple=""
                                            data-placeholder="اختر الجمعيات">
                                        <option value="0"{if 0|in_array:$loadData->charityids} selected="selected" {/if}>كل الجمعيات </option>
                                        {foreach $allCharities as $charity}
                                        <option value="{$charity.id}" {if $charity.id|in_array:$loadData->charityids}
                                            selected="selected" {/if}>{$charity.charityname}</option>
                                        {/foreach}
                                    </select>
                                    <span class="selectInvalidMsg"> *</span></span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="userstoreid" class="col-lg-2 control-label">مستخدمين النقدى الاجل</label>
                            <div class="col-lg-4">

                                <span id="spryselect4">
                                    <select class="select2 wdt100" name="laterNakdiUserIds[]" id="laterNakdiUserIds" multiple=""
                                            data-placeholder="اختر المستخدمين">
                                        <option value="0" {if 0|in_array:$loadData->laterNakdiUserIds} selected="selected" {/if}>كل المستخدمين </option>
                                        {foreach $allUsers as $data}
                                        <option value="{$data['userid']}" {if $data['userid']|in_array:$loadData->laterNakdiUserIds}
                                            selected="selected" {/if}>{$data['employeename']}</option>
                                        {/foreach}

                                    </select>
                                    <span class="selectInvalidMsg"> *</span></span>
                            </div>
                        </div>


                        <!--==============================-->

                    </div>



                    <input type="hidden" name="userid" id="userid" value="{$loadData->userid}" />
                    <input type="hidden" name="currentdate" value="{$loadData->currentdate}" />
                    <input type="hidden" name="conditions" value="{$loadData->conditions}" />





                    <div class="form-group">
                        <div class="col-lg-offset-2 col-lg-4">
                            <button type="button" class="btn btn-primary pull-left" id="spbutton">حفظ الامر</button>
                        </div>
                    </div>




                </form>
            </div>
        </div>




    </div>
</div>



{literal}
<script type="text/javascript">
    var name = new Spry.Widget.ValidationTextField("name");
    var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
    var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
    var spryselect2 = new Spry.Widget.ValidationSelect("spryselect2", {invalidValue: "-1", isRequired: false});
    var spryselect3 = new Spry.Widget.ValidationSelect("spryselect3", {isRequired: false, invalidValue: "-1"});
    var spryselect4 = new Spry.Widget.ValidationSelect("spryselect4", {isRequired: false, invalidValue: "-1"});
    var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "real", {isRequired: false, invalidValue: "-1", minValue: "0", maxValue: "100"});
    var spryselect5;
    // $('#userstoreid').live('change', function () {
    //     var val = Number($(this).val());
    //     if (val == 0) {
    //         spryselect5 = new Spry.Widget.ValidationSelect("spryselect5", {isRequired: false, invalidValue: "-1"});
    //     } else {
    //         spryselect5.destroy();
    //     }
    // });
    // $('#userstoreid').change();
    $('input[name="storeSupervisor"]').live('change', function () {
        if ($('input[name="storeSupervisor"]:checked').val() == 1) {
            $('#storeSupervisorStoresDiv').show();
        } else {
            $('#storeSupervisorStoresDiv').hide();
        }
    });
    $('input[name="storeSupervisor"]').change();

    $('input[name="searchinonesave"]').live('change', function () {
        if ($('input[name="searchinonesave"]:checked').val() == 1) {
            $('#saveidshow').hide();
        } else {
            $('#saveidshow').show();
        }
    });

    $('#userstoreid').live('change', function () {
        if ($(this).val() == 0) {
            $('#storeidshow').show();
        } else {
            $('#storeidshow').hide();
        }
    });

</script>
{/literal}
{literal}
<script type="text/javascript">
    $('#spbutton').live('click', function (e) {
        //ckeck name
        var tableName = 'user';
        var inputName = 'username';
        var name = $("#" + inputName).val();
        var id = $("#userid").val();
        $.ajax({
            url: 'checkRedundantNames.php?do=checkNameWithId&name=' + name + '&id=' + id + '&tablename=' + tableName,
            success: function (data) {
                //alert(data);
                if (data == '0') {
                    $("#nameError").css("display", "none");
                    var myForm = document.getElementById("spform");
                    var SS = Spry.Widget.Form.validate(myForm);
                    if (SS == true) {
                        if (!$('#spbutton').hasClass("processing")) {
                            $('#spbutton').addClass("processing");
                            myForm.submit();
                            //$('#spbutton').unbind('click');
                        }
                    }

                } else if (data == '1') {
                    $("#" + inputName).val("");
                    $("#" + inputName).focus();
                    $("#nameError").css("display", "block");
                    return false;
                }
            }
        });

    });
</script>
{/literal}